In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
Writing to a file
Writing to a file
What's the best way to write to a text file, in Xailer? It's obvious in the
OzLib or FW libraries; you just use the TTXTFILE class. Or you can use the
standard SET ALTERNATE TO for Xbase. But is there an offical way to write
to a text file, in Xailer?
OzLib or FW libraries; you just use the TTXTFILE class. Or you can use the
standard SET ALTERNATE TO for Xbase. But is there an offical way to write
to a text file, in Xailer?
Writing to a file
DGauss,
> What's the best way to write to a text file, in Xailer? It's obvious in the
> OzLib or FW libraries; you just use the TTXTFILE class. Or you can use the
> standard SET ALTERNATE TO for Xbase. But is there an offical way to write
> to a text file, in Xailer?
There are a lot of ways to do it. You can use MemoWrit, FOpen/FWrite, etc.
it depends on your needs. If you explain what want to achieve we can help
you better.
Regards,
José Lalín
> What's the best way to write to a text file, in Xailer? It's obvious in the
> OzLib or FW libraries; you just use the TTXTFILE class. Or you can use the
> standard SET ALTERNATE TO for Xbase. But is there an offical way to write
> to a text file, in Xailer?
There are a lot of ways to do it. You can use MemoWrit, FOpen/FWrite, etc.
it depends on your needs. If you explain what want to achieve we can help
you better.
Regards,
José Lalín
Writing to a file
>>There are a lot of ways to do it. You can use MemoWrit, FOpen/FWrite, etc.
it depends on your needs. If you explain what want to achieve we can help
you better.<<
I was hoping for a generic class or the use of FileSystemObject from the
Windows scripting api.
In fact, just SET PRINTER TO is working fine in my code, in combination with
'?' statements. It just seems unnatural at this point, i.e. a file class
would seem more natural and generic.
it depends on your needs. If you explain what want to achieve we can help
you better.<<
I was hoping for a generic class or the use of FileSystemObject from the
Windows scripting api.
In fact, just SET PRINTER TO is working fine in my code, in combination with
'?' statements. It just seems unnatural at this point, i.e. a file class
would seem more natural and generic.
Writing to a file
here is a fileio class that i like to use
/*í‰í Program
íííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí íííí»
º Application: Program/Class Development
º
º Description: file class
º
º File Name: FILEIO.PRG
º
º Author: L. M. Skousen
º
º Date created: 03-19-02 Date updated: í¾03-19-02
º
º Time created: 05:15:15pm Time updated: í¾05:15:15pm
º
º Make File: MAKEFILE
º
º Exec File: .exe Docs By: L. M. Skousen
º
í‡í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„¶
º Revisions:
º
º
º
íˆííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí ííííííííííííííí¼
*/
// #include "class(y).ch"
#include "hbclass.ch"
#include "common.ch"
#include "fileio.ch"
// for what32 ::saveto()
#include "commdlg.ch"
create class fileio
export:
var nHandle
var cFile // path and file name and ext
var nError
var nAccess
var nShare
var nAttribute
var lBreak
var nWriteLines // count the number of lines written
method Init
method GoTop
method Position
method GoTo
method GoBottom
method Size
method Ready
method Open
method ReadSome
method WriteSome
method Close
method Path
method Name
method Ext
method Exists
method Erase
method Rename
method WhatsWrong
method FileError
method ErrorBreak
method SaveTo
endclass
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: init()
³
³ Description: class constructor
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:37:38am Time updated: í¾10:37:38am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: cFileName - path and filename+extention of requested
file ³
³ : nMode - file share and access mode (fileio.ch
FO_stuff) ³
³ Return Value: Self
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Init(cFileName,nMode)
default cFileName to "Temp.txt"
default nMode to FO_READWRITE+FO_SHARED
::cFile := cFileName
::nError := 0
::nAttribute := FC_NORMAL
::nAccess := nMode%16
::nShare := nMode - ::nAccess
::lBreak := .f.
::nWriteLines := 0
return (Self)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: gotop()
³
³ Description: move pointer position to top of file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:44:10am Time updated: í¾10:44:10am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoTop()
local lSuccess := .f.
if ::ready()
lSuccess := (fseek(::nHandle,0) == 0)
::FileError(ferror())
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: position()
³
³ Description: give position of file position pointer in bytes
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:58:39am Time updated: í¾10:58:39am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: nReturn - current position of pointer from top of
file ³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Position()
local nReturn
if ::ready()
nReturn := fseek(::nHandle,0,FS_RELATIVE)
::FileError(ferror())
endif
return (nReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: goto()
³
³ Description: move file pointer to a new specified position
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:20:33am Time updated: í¾11:20:33am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: nBytes - number of bytes to move, may be + or -
³
³ : [nOrigin] - move is relative to 0-top 1-current
2-bottom ³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoTo(nBytes,nOrigin)
local lSuccess := .f.
default nOrigin to FS_SET
if ::ready()
fseek(::nHandle,nBytes,nOrigin)
lSuccess := (::FileError(ferror()) == 0)
endi
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: gobottom()
³
³ Description: set position of file pointer to bottom of file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:06:38am Time updated: í¾11:06:38am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoBottom()
local lSuccess := .f.
if ::ready()
fseek(::nHandle,0,FS_END)
lSuccess := (::FileError(ferror()) == 0)
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ready()
³
³ Description: check if file is ready for operation, if not, open it
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:48:22am Time updated: í¾11:48:22am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Ready()
local lSuccess := .t.
::FileError(0)
if ::nHandle == nil .or. ::nHandle < 0
::nHandle := nil
lSuccess := ::open()
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: open()
³
³ Description: open (or create) a file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:44:37am Time updated: í¾10:44:37am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: [nMode] - is access and share mode, same as fopen
func mode³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Open(nMode)
local lSuccess := .t.
if !(pcount()==0)
::nAccess := nMode%16
::nShare := nMode - ::nAccess
endif
if !empty(::nHandle)
::close()
endif
if ! ::exists()
::nHandle := fcreate(::cFile,::nAttribute)
else
::nHandle := fopen(::cFile,::nAccess+::nShare)
endif
if ::nHandle < 0
::FileError(ferror())
lSuccess := .f.
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: size()
³
³ Description: report on file length
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:59:57am Time updated: í¾11:59:57am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: size of file in bytes
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Size()
local nOldPos
local nReturn
nOldPos := ::position()
if ::FileError() == 0 .and. ::gobottom()
nReturn := ::position()
if ::FileError() == 0
::goto(nOldPos)
endif
endif
return (nReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: writesome()
³
³ Description: write to a file additive
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 01:04:05pm Time updated: í¾01:04:05pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: xMessage
³
³ : lCRLF - if added carrage return, line feed pair
wanted ³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method WriteSome(xMessage,lCRLF)
local lSuccess := .f.
default lCRLF to .t.
if ::ready()
if valtype(xMessage) == "A"
lSuccess := .t.
aeval(xMessage,{|ele| lSuccess := lSuccess .and.
::writesome(ele,lCRLF)})
else
::gobottom()
if !(lSuccess :=
(fwrite(::nHandle,xMessage+if(lCRLF,(::nWriteLines++,chr(13) +chr(10)), ""))>0))
::FileError(ferror())
endi
endif
endi
return(lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ReadSome()
³
³ Description: read from a file from current position
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:31:14pm Time updated: í¾12:31:14pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: xUntil - delimiter str look for or number of bytes
³
³ Arguments: lForward - true(default)=forward, false=backward
³
³ Return Value: cReturn - read part
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method ReadSome(xUntil,lForward)
local cReturn := ""
local cBuffer
local nCount := 0
local nRead
local nPosition
default xUntil to (chr(13)+chr(10))
default lForward to .t.
if ::ready()
do case
case valtype(xUntil) == "C" // delimit character/str
do while nCount < 65536 .and. len(cReturn) == nCount
cBuffer := ::readsome(1024,lForward)
nCount := nCount+1024
if lForward
nPosition := at(xUntil,cBuffer)
else // lBackward
nPosition := rat(xUntil,cBuffer)
endif
if nPosition > 0
if lForward
cReturn := cReturn+left(cBuffer,nPosition+len(xUntil)-1)
::goto((nPosition+len(xUntil)-1)-len(cBuffer),FS_RELATIVE)
else // lBackward
cReturn := substr(cBuffer,nPosition)+cReturn
::goto(nPosition-1,FS_RELATIVE)
endi
else
if lForward
cReturn := cReturn+cBuffer
else // lBackward
cReturn := cBuffer+cReturn
endi
endif
enddo
case valtype(xUntil) == "N" // number of bytes
cBuffer := space(xUntil)
if !lForward // backwards
nPosition := ::position()
xUntil := min(xUntil,nPosition)
::goto(nPosition-xUntil)
endif
nRead := fread(::nHandle,@cBuffer,xUntil)
cReturn := left(cBuffer,nRead)
if !lForward // backwards
::goto(nPosition-xUntil)
endif
endc
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: close()
³
³ Description: close a file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:21:53pm Time updated: í¾12:21:53pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Close()
local lSuccess := .t.
if !(::nHandle==nil) .and. ::nHandle >= 0
lSuccess := !fclose(::nHandle)
::nHandle := nil
::FileError(ferror())
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: exists()
³
³ Description: check if file exists
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:19:14pm Time updated: í¾12:19:14pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: file(::cFile) true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Exists()
return (file(::cFile))
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Path()
³
³ Description: returns the path of cFile
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:45:00pm Time updated: í¾12:45:00pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Path()
local cReturn := ""
local nPosition := rat("",::cFile)
if nPosition > 0
cReturn := left(::cFile,nPosition)
else
cReturn := curdir()
if !empty(cReturn)
cReturn := ""+cReturn
endif
cReturn := cReturn+""
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Name()
³
³ Description: returns just the name part of cFile, no path no
extention ³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:57:53pm Time updated: í¾12:57:53pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Name()
local cReturn := ""
local nPosition := rat("",::cFile)
if nPosition > 0
cReturn := substr(::cFile,nPosition+1)
else
cReturn := ::cFile
endi
nPosition := rat(".",cReturn)
if nPosition > 0
cReturn := left(cReturn,nPosition-1)
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Ext()
³
³ Description: return the extention from a file name
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:42:13pm Time updated: í¾12:42:13pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Ext()
local cReturn := ""
local nPosition := rat(".",::cFile)
if nPosition > 0
cReturn := substr(::cFile,nPosition+1)
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Erase()
³
³ Description: delete the file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 05:32:34pm Time updated: í¾05:32:34pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Erase()
local lSuccess := .f.
if !(::nHandle==nil) .and. ::nHandle >= 0
::close()
endi
if ::nHandle == nil
lSuccess := (fErase(::cFile)==0)
::FileError(ferror())
endi
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Rename()
³
³ Description: rename the file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 05:43:45pm Time updated: í¾05:43:45pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: cNewName - the new name for the file
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Rename(cNewName)
local lSuccess := .f.
if !(::nHandle==nil) .and. ::nHandle >= 0
::close()
endi
if ::nHandle == nil
lSuccess := (frename(::cFile,cNewName)==0)
::FileError(ferror())
if lSuccess
::cFile := cNewName
endif
endi
return(lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: FileError()
³
³ Description: set/get Error number
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 12:30:58pm Time updated: í¾12:30:58pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: nError
³
³ Return Value: nError
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method FileError(nError)
if pcount() > 0
::nError := nError
if nError > 0
alert("File Error for:;"+::cfile+";"+::whatswrong())
if ::ErrorBreak()
break
endif
endi
endif
return(::nError)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: WhatsWrong()
³
³ Description: Tell what the error is
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 11:20:46am Time updated: í¾11:20:46am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cError - error string
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method WhatsWrong(nError)
local cError := "UnKnown"
local aError := {;
{0 ,"Successful"},;
{2 ,"File not found"},;
{3 ,"Path not found"},;
{4 ,"Too many files open"},;
{5 ,"Access denied"},;
{6 ,"Invalid handle"},;
{8 ,"Insufficient memory"},;
{15,"Invalid drive specified"},;
{19,"Attempted to write to a write-protected disk"},;
{21,"Drive not ready"},;
{23,"Data CRC error"},;
{29,"Write fault"},;
{30,"Read fault"},;
{32,"Sharing violation"},;
{33,"Lock Violation"}}
default nError to ::nError
if (nError := ascan(aError,{|ele| ele[1] == nError })) > 0
cError := aError[nError,2]
endif
return(cError)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ErrorBreak()
³
³ Description: get/set for error break variable
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 12:46:19pm Time updated: í¾12:46:19pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: lBreak
³
³ Return Value: ::lBreak
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method ErrorBreak(lBreak)
if pcount() > 0
::lBreak := lBreak
endif
return(::lBreak)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: SaveTo()
³
³ Description: save the file to somewhere
³
³ Author: L. M. Skousen
³
³ Date created: 01/20/06 Date updated: í¾01/20/06
³
³ Time created: 11:34:05pm Time updated: í¾11:34:05pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: Self
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method SaveTo()
local cFileName
local aFilter := {{"CSV Files","*.csv"},{"All Files","*.*"}}
cFileName := getsavefilename(;
getactivewindow(),; // hWnd:
::Name()+"."+::Ext(),; // cFile:
"Save Processed Data",; // cTitle:
aFilter,; // aFilter:
OFN_EXPLORER+OFN_NOCHANGEDIR,; // nFlags:
::Path(),; // cInitDir:
"csv",; // cDefExt:
1) // nIndex:
if !empty(cFileName)
::rename(cFileName)
endif
return(::cFile)
DGauss wrote:
>>> There are a lot of ways to do it. You can use MemoWrit, FOpen/FWrite, etc.
>
> it depends on your needs. If you explain what want to achieve we can help
>
> you better.<<
>
> I was hoping for a generic class or the use of FileSystemObject from the
> Windows scripting api.
>
> In fact, just SET PRINTER TO is working fine in my code, in combination with
> '?' statements. It just seems unnatural at this point, i.e. a file class
> would seem more natural and generic.
>
>
>
/*í‰í Program
íííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí íííí»
º Application: Program/Class Development
º
º Description: file class
º
º File Name: FILEIO.PRG
º
º Author: L. M. Skousen
º
º Date created: 03-19-02 Date updated: í¾03-19-02
º
º Time created: 05:15:15pm Time updated: í¾05:15:15pm
º
º Make File: MAKEFILE
º
º Exec File: .exe Docs By: L. M. Skousen
º
í‡í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„¶
º Revisions:
º
º
º
íˆííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí ííííííííííííííí¼
*/
// #include "class(y).ch"
#include "hbclass.ch"
#include "common.ch"
#include "fileio.ch"
// for what32 ::saveto()
#include "commdlg.ch"
create class fileio
export:
var nHandle
var cFile // path and file name and ext
var nError
var nAccess
var nShare
var nAttribute
var lBreak
var nWriteLines // count the number of lines written
method Init
method GoTop
method Position
method GoTo
method GoBottom
method Size
method Ready
method Open
method ReadSome
method WriteSome
method Close
method Path
method Name
method Ext
method Exists
method Erase
method Rename
method WhatsWrong
method FileError
method ErrorBreak
method SaveTo
endclass
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: init()
³
³ Description: class constructor
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:37:38am Time updated: í¾10:37:38am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: cFileName - path and filename+extention of requested
file ³
³ : nMode - file share and access mode (fileio.ch
FO_stuff) ³
³ Return Value: Self
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Init(cFileName,nMode)
default cFileName to "Temp.txt"
default nMode to FO_READWRITE+FO_SHARED
::cFile := cFileName
::nError := 0
::nAttribute := FC_NORMAL
::nAccess := nMode%16
::nShare := nMode - ::nAccess
::lBreak := .f.
::nWriteLines := 0
return (Self)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: gotop()
³
³ Description: move pointer position to top of file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:44:10am Time updated: í¾10:44:10am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoTop()
local lSuccess := .f.
if ::ready()
lSuccess := (fseek(::nHandle,0) == 0)
::FileError(ferror())
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: position()
³
³ Description: give position of file position pointer in bytes
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:58:39am Time updated: í¾10:58:39am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: nReturn - current position of pointer from top of
file ³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Position()
local nReturn
if ::ready()
nReturn := fseek(::nHandle,0,FS_RELATIVE)
::FileError(ferror())
endif
return (nReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: goto()
³
³ Description: move file pointer to a new specified position
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:20:33am Time updated: í¾11:20:33am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: nBytes - number of bytes to move, may be + or -
³
³ : [nOrigin] - move is relative to 0-top 1-current
2-bottom ³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoTo(nBytes,nOrigin)
local lSuccess := .f.
default nOrigin to FS_SET
if ::ready()
fseek(::nHandle,nBytes,nOrigin)
lSuccess := (::FileError(ferror()) == 0)
endi
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: gobottom()
³
³ Description: set position of file pointer to bottom of file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:06:38am Time updated: í¾11:06:38am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method GoBottom()
local lSuccess := .f.
if ::ready()
fseek(::nHandle,0,FS_END)
lSuccess := (::FileError(ferror()) == 0)
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ready()
³
³ Description: check if file is ready for operation, if not, open it
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:48:22am Time updated: í¾11:48:22am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Ready()
local lSuccess := .t.
::FileError(0)
if ::nHandle == nil .or. ::nHandle < 0
::nHandle := nil
lSuccess := ::open()
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: open()
³
³ Description: open (or create) a file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 10:44:37am Time updated: í¾10:44:37am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: [nMode] - is access and share mode, same as fopen
func mode³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Open(nMode)
local lSuccess := .t.
if !(pcount()==0)
::nAccess := nMode%16
::nShare := nMode - ::nAccess
endif
if !empty(::nHandle)
::close()
endif
if ! ::exists()
::nHandle := fcreate(::cFile,::nAttribute)
else
::nHandle := fopen(::cFile,::nAccess+::nShare)
endif
if ::nHandle < 0
::FileError(ferror())
lSuccess := .f.
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: size()
³
³ Description: report on file length
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 11:59:57am Time updated: í¾11:59:57am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: size of file in bytes
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Size()
local nOldPos
local nReturn
nOldPos := ::position()
if ::FileError() == 0 .and. ::gobottom()
nReturn := ::position()
if ::FileError() == 0
::goto(nOldPos)
endif
endif
return (nReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: writesome()
³
³ Description: write to a file additive
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 01:04:05pm Time updated: í¾01:04:05pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: xMessage
³
³ : lCRLF - if added carrage return, line feed pair
wanted ³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method WriteSome(xMessage,lCRLF)
local lSuccess := .f.
default lCRLF to .t.
if ::ready()
if valtype(xMessage) == "A"
lSuccess := .t.
aeval(xMessage,{|ele| lSuccess := lSuccess .and.
::writesome(ele,lCRLF)})
else
::gobottom()
if !(lSuccess :=
(fwrite(::nHandle,xMessage+if(lCRLF,(::nWriteLines++,chr(13) +chr(10)), ""))>0))
::FileError(ferror())
endi
endif
endi
return(lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ReadSome()
³
³ Description: read from a file from current position
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:31:14pm Time updated: í¾12:31:14pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: xUntil - delimiter str look for or number of bytes
³
³ Arguments: lForward - true(default)=forward, false=backward
³
³ Return Value: cReturn - read part
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method ReadSome(xUntil,lForward)
local cReturn := ""
local cBuffer
local nCount := 0
local nRead
local nPosition
default xUntil to (chr(13)+chr(10))
default lForward to .t.
if ::ready()
do case
case valtype(xUntil) == "C" // delimit character/str
do while nCount < 65536 .and. len(cReturn) == nCount
cBuffer := ::readsome(1024,lForward)
nCount := nCount+1024
if lForward
nPosition := at(xUntil,cBuffer)
else // lBackward
nPosition := rat(xUntil,cBuffer)
endif
if nPosition > 0
if lForward
cReturn := cReturn+left(cBuffer,nPosition+len(xUntil)-1)
::goto((nPosition+len(xUntil)-1)-len(cBuffer),FS_RELATIVE)
else // lBackward
cReturn := substr(cBuffer,nPosition)+cReturn
::goto(nPosition-1,FS_RELATIVE)
endi
else
if lForward
cReturn := cReturn+cBuffer
else // lBackward
cReturn := cBuffer+cReturn
endi
endif
enddo
case valtype(xUntil) == "N" // number of bytes
cBuffer := space(xUntil)
if !lForward // backwards
nPosition := ::position()
xUntil := min(xUntil,nPosition)
::goto(nPosition-xUntil)
endif
nRead := fread(::nHandle,@cBuffer,xUntil)
cReturn := left(cBuffer,nRead)
if !lForward // backwards
::goto(nPosition-xUntil)
endif
endc
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: close()
³
³ Description: close a file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:21:53pm Time updated: í¾12:21:53pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Close()
local lSuccess := .t.
if !(::nHandle==nil) .and. ::nHandle >= 0
lSuccess := !fclose(::nHandle)
::nHandle := nil
::FileError(ferror())
endif
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: exists()
³
³ Description: check if file exists
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:19:14pm Time updated: í¾12:19:14pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: file(::cFile) true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Exists()
return (file(::cFile))
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Path()
³
³ Description: returns the path of cFile
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:45:00pm Time updated: í¾12:45:00pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Path()
local cReturn := ""
local nPosition := rat("",::cFile)
if nPosition > 0
cReturn := left(::cFile,nPosition)
else
cReturn := curdir()
if !empty(cReturn)
cReturn := ""+cReturn
endif
cReturn := cReturn+""
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Name()
³
³ Description: returns just the name part of cFile, no path no
extention ³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:57:53pm Time updated: í¾12:57:53pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Name()
local cReturn := ""
local nPosition := rat("",::cFile)
if nPosition > 0
cReturn := substr(::cFile,nPosition+1)
else
cReturn := ::cFile
endi
nPosition := rat(".",cReturn)
if nPosition > 0
cReturn := left(cReturn,nPosition-1)
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Ext()
³
³ Description: return the extention from a file name
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 12:42:13pm Time updated: í¾12:42:13pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cReturn
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Ext()
local cReturn := ""
local nPosition := rat(".",::cFile)
if nPosition > 0
cReturn := substr(::cFile,nPosition+1)
endif
return (cReturn)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Erase()
³
³ Description: delete the file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 05:32:34pm Time updated: í¾05:32:34pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Erase()
local lSuccess := .f.
if !(::nHandle==nil) .and. ::nHandle >= 0
::close()
endi
if ::nHandle == nil
lSuccess := (fErase(::cFile)==0)
::FileError(ferror())
endi
return (lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: Rename()
³
³ Description: rename the file
³
³ Author: L. M. Skousen
³
³ Date created: 03-20-02 Date updated: í¾03-20-02
³
³ Time created: 05:43:45pm Time updated: í¾05:43:45pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: cNewName - the new name for the file
³
³ Return Value: lSuccess - true or false
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method Rename(cNewName)
local lSuccess := .f.
if !(::nHandle==nil) .and. ::nHandle >= 0
::close()
endi
if ::nHandle == nil
lSuccess := (frename(::cFile,cNewName)==0)
::FileError(ferror())
if lSuccess
::cFile := cNewName
endif
endi
return(lSuccess)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: FileError()
³
³ Description: set/get Error number
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 12:30:58pm Time updated: í¾12:30:58pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: nError
³
³ Return Value: nError
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method FileError(nError)
if pcount() > 0
::nError := nError
if nError > 0
alert("File Error for:;"+::cfile+";"+::whatswrong())
if ::ErrorBreak()
break
endif
endi
endif
return(::nError)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: WhatsWrong()
³
³ Description: Tell what the error is
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 11:20:46am Time updated: í¾11:20:46am
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: cError - error string
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method WhatsWrong(nError)
local cError := "UnKnown"
local aError := {;
{0 ,"Successful"},;
{2 ,"File not found"},;
{3 ,"Path not found"},;
{4 ,"Too many files open"},;
{5 ,"Access denied"},;
{6 ,"Invalid handle"},;
{8 ,"Insufficient memory"},;
{15,"Invalid drive specified"},;
{19,"Attempted to write to a write-protected disk"},;
{21,"Drive not ready"},;
{23,"Data CRC error"},;
{29,"Write fault"},;
{30,"Read fault"},;
{32,"Sharing violation"},;
{33,"Lock Violation"}}
default nError to ::nError
if (nError := ascan(aError,{|ele| ele[1] == nError })) > 0
cError := aError[nError,2]
endif
return(cError)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: ErrorBreak()
³
³ Description: get/set for error break variable
³
³ Author: L. M. Skousen
³
³ Date created: 03/24/04 Date updated: í¾03/24/04
³
³ Time created: 12:46:19pm Time updated: í¾12:46:19pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: lBreak
³
³ Return Value: ::lBreak
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method ErrorBreak(lBreak)
if pcount() > 0
::lBreak := lBreak
endif
return(::lBreak)
/*íší„ Method
í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
³ Name: SaveTo()
³
³ Description: save the file to somewhere
³
³ Author: L. M. Skousen
³
³ Date created: 01/20/06 Date updated: í¾01/20/06
³
³ Time created: 11:34:05pm Time updated: í¾11:34:05pm
³
íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
³ Arguments: None
³
³ Return Value: Self
³
í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
*/
method SaveTo()
local cFileName
local aFilter := {{"CSV Files","*.csv"},{"All Files","*.*"}}
cFileName := getsavefilename(;
getactivewindow(),; // hWnd:
::Name()+"."+::Ext(),; // cFile:
"Save Processed Data",; // cTitle:
aFilter,; // aFilter:
OFN_EXPLORER+OFN_NOCHANGEDIR,; // nFlags:
::Path(),; // cInitDir:
"csv",; // cDefExt:
1) // nIndex:
if !empty(cFileName)
::rename(cFileName)
endif
return(::cFile)
DGauss wrote:
>>> There are a lot of ways to do it. You can use MemoWrit, FOpen/FWrite, etc.
>
> it depends on your needs. If you explain what want to achieve we can help
>
> you better.<<
>
> I was hoping for a generic class or the use of FileSystemObject from the
> Windows scripting api.
>
> In fact, just SET PRINTER TO is working fine in my code, in combination with
> '?' statements. It just seems unnatural at this point, i.e. a file class
> would seem more natural and generic.
>
>
>
Writing to a file
DGauss,
> I was hoping for a generic class or the use of FileSystemObject from the
> Windows scripting api.
>
> In fact, just SET PRINTER TO is working fine in my code, in combination with
> '?' statements. It just seems unnatural at this point, i.e. a file class
> would seem more natural and generic.
Yes, you are right. I will return to this subject once I get some spare time.
Regards,
José Lalín
> I was hoping for a generic class or the use of FileSystemObject from the
> Windows scripting api.
>
> In fact, just SET PRINTER TO is working fine in my code, in combination with
> '?' statements. It just seems unnatural at this point, i.e. a file class
> would seem more natural and generic.
Yes, you are right. I will return to this subject once I get some spare time.
Regards,
José Lalín
Writing to a file
>>Yes, you are right. I will return to this subject once I get some spare
time.<<
Sounds good, Thanks. Meanwhile, Xbase's native commands are working fine.
time.<<
Sounds good, Thanks. Meanwhile, Xbase's native commands are working fine.
Writing to a file
Thanks, chief. I'll probably just use the native commands, until Xailer has
an alternative, or link in some of the OZ/FW code if necessary.
an alternative, or link in some of the OZ/FW code if necessary.
Writing to a file
it work automagically very easy.
just:
// writing
oFile := fileio():new("c:somepathwritefile.txt")
oFile:writesome("this is a line")
oFile:close()
// reading
oFile := fileio():new("c:somepathreadfile.txt")
cLine := oFile:readsome()
oFile:close()
automatically handles creation/opening and closing (when needed) and
file handles for you.
with many options
dan
user@domain.invalid wrote:
> here is a fileio class that i like to use
>
>
> /*í‰í Program
> íííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí íííí»
> º Application: Program/Class Development º
> º Description: file class º
> º File Name: FILEIO.PRG º
> º Author: L. M. Skousen º
> º Date created: 03-19-02 Date updated: í¾03-19-02 º
> º Time created: 05:15:15pm Time updated: í¾05:15:15pm º
> º Make File: MAKEFILE º
> º Exec File: .exe Docs By: L. M. Skousen º
>
> í‡í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„¶
>
> º Revisions: º
> º º
>
> íˆííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí ííííííííííííííí¼
>
> */
>
> // #include "class(y).ch"
> #include "hbclass.ch"
> #include "common.ch"
> #include "fileio.ch"
> // for what32 ::saveto()
> #include "commdlg.ch"
>
>
> create class fileio
> export:
> var nHandle
> var cFile // path and file name and ext
> var nError
> var nAccess
> var nShare
> var nAttribute
> var lBreak
> var nWriteLines // count the number of lines written
>
> method Init
> method GoTop
> method Position
> method GoTo
> method GoBottom
> method Size
> method Ready
> method Open
> method ReadSome
> method WriteSome
> method Close
> method Path
> method Name
> method Ext
> method Exists
> method Erase
> method Rename
> method WhatsWrong
> method FileError
> method ErrorBreak
> method SaveTo
>
> endclass
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: init() ³
> ³ Description: class constructor ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:37:38am Time updated: í¾10:37:38am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: cFileName - path and filename+extention of requested
> file ³
> ³ : nMode - file share and access mode (fileio.ch
> FO_stuff) ³
> ³ Return Value: Self ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Init(cFileName,nMode)
> default cFileName to "Temp.txt"
> default nMode to FO_READWRITE+FO_SHARED
> ::cFile := cFileName
> ::nError := 0
> ::nAttribute := FC_NORMAL
> ::nAccess := nMode%16
> ::nShare := nMode - ::nAccess
> ::lBreak := .f.
> ::nWriteLines := 0
> return (Self)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: gotop() ³
> ³ Description: move pointer position to top of file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:44:10am Time updated: í¾10:44:10am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoTop()
> local lSuccess := .f.
> if ::ready()
> lSuccess := (fseek(::nHandle,0) == 0)
> ::FileError(ferror())
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: position() ³
> ³ Description: give position of file position pointer in bytes ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:58:39am Time updated: í¾10:58:39am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: nReturn - current position of pointer from top of
> file ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Position()
> local nReturn
> if ::ready()
> nReturn := fseek(::nHandle,0,FS_RELATIVE)
> ::FileError(ferror())
> endif
> return (nReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: goto() ³
> ³ Description: move file pointer to a new specified position ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:20:33am Time updated: í¾11:20:33am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: nBytes - number of bytes to move, may be + or - ³
> ³ : [nOrigin] - move is relative to 0-top 1-current
> 2-bottom ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoTo(nBytes,nOrigin)
> local lSuccess := .f.
> default nOrigin to FS_SET
> if ::ready()
> fseek(::nHandle,nBytes,nOrigin)
> lSuccess := (::FileError(ferror()) == 0)
> endi
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: gobottom() ³
> ³ Description: set position of file pointer to bottom of file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:06:38am Time updated: í¾11:06:38am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoBottom()
> local lSuccess := .f.
> if ::ready()
> fseek(::nHandle,0,FS_END)
> lSuccess := (::FileError(ferror()) == 0)
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ready() ³
> ³ Description: check if file is ready for operation, if not, open it
> ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:48:22am Time updated: í¾11:48:22am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Ready()
> local lSuccess := .t.
> ::FileError(0)
> if ::nHandle == nil .or. ::nHandle < 0
> ::nHandle := nil
> lSuccess := ::open()
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: open() ³
> ³ Description: open (or create) a file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:44:37am Time updated: í¾10:44:37am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: [nMode] - is access and share mode, same as fopen func
> mode³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Open(nMode)
> local lSuccess := .t.
> if !(pcount()==0)
> ::nAccess := nMode%16
> ::nShare := nMode - ::nAccess
> endif
> if !empty(::nHandle)
> ::close()
> endif
> if ! ::exists()
> ::nHandle := fcreate(::cFile,::nAttribute)
> else
> ::nHandle := fopen(::cFile,::nAccess+::nShare)
> endif
> if ::nHandle < 0
> ::FileError(ferror())
> lSuccess := .f.
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: size() ³
> ³ Description: report on file length ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:59:57am Time updated: í¾11:59:57am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: size of file in bytes ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Size()
> local nOldPos
> local nReturn
> nOldPos := ::position()
> if ::FileError() == 0 .and. ::gobottom()
> nReturn := ::position()
> if ::FileError() == 0
> ::goto(nOldPos)
> endif
> endif
> return (nReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: writesome() ³
> ³ Description: write to a file additive ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 01:04:05pm Time updated: í¾01:04:05pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: xMessage ³
> ³ : lCRLF - if added carrage return, line feed pair
> wanted ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method WriteSome(xMessage,lCRLF)
> local lSuccess := .f.
> default lCRLF to .t.
> if ::ready()
> if valtype(xMessage) == "A"
> lSuccess := .t.
> aeval(xMessage,{|ele| lSuccess := lSuccess .and.
> ::writesome(ele,lCRLF)})
> else
> ::gobottom()
> if !(lSuccess :=
> (fwrite(::nHandle,xMessage+if(lCRLF,(::nWriteLines++,chr(13) +chr(10)), ""))>0))
>
> ::FileError(ferror())
> endi
> endif
> endi
> return(lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ReadSome() ³
> ³ Description: read from a file from current position ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:31:14pm Time updated: í¾12:31:14pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: xUntil - delimiter str look for or number of bytes
> ³
> ³ Arguments: lForward - true(default)=forward, false=backward ³
> ³ Return Value: cReturn - read part ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method ReadSome(xUntil,lForward)
> local cReturn := ""
> local cBuffer
> local nCount := 0
> local nRead
> local nPosition
> default xUntil to (chr(13)+chr(10))
> default lForward to .t.
> if ::ready()
> do case
> case valtype(xUntil) == "C" // delimit character/str
> do while nCount < 65536 .and. len(cReturn) == nCount
> cBuffer := ::readsome(1024,lForward)
> nCount := nCount+1024
> if lForward
> nPosition := at(xUntil,cBuffer)
> else // lBackward
> nPosition := rat(xUntil,cBuffer)
> endif
> if nPosition > 0
> if lForward
> cReturn := cReturn+left(cBuffer,nPosition+len(xUntil)-1)
> ::goto((nPosition+len(xUntil)-1)-len(cBuffer),FS_RELATIVE)
> else // lBackward
> cReturn := substr(cBuffer,nPosition)+cReturn
> ::goto(nPosition-1,FS_RELATIVE)
> endi
> else
> if lForward
> cReturn := cReturn+cBuffer
> else // lBackward
> cReturn := cBuffer+cReturn
> endi
> endif
> enddo
> case valtype(xUntil) == "N" // number of bytes
> cBuffer := space(xUntil)
> if !lForward // backwards
> nPosition := ::position()
> xUntil := min(xUntil,nPosition)
> ::goto(nPosition-xUntil)
> endif
> nRead := fread(::nHandle,@cBuffer,xUntil)
> cReturn := left(cBuffer,nRead)
> if !lForward // backwards
> ::goto(nPosition-xUntil)
> endif
> endc
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: close() ³
> ³ Description: close a file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:21:53pm Time updated: í¾12:21:53pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Close()
> local lSuccess := .t.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> lSuccess := !fclose(::nHandle)
> ::nHandle := nil
> ::FileError(ferror())
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: exists() ³
> ³ Description: check if file exists ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:19:14pm Time updated: í¾12:19:14pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: file(::cFile) true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Exists()
> return (file(::cFile))
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Path() ³
> ³ Description: returns the path of cFile ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:45:00pm Time updated: í¾12:45:00pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Path()
> local cReturn := ""
> local nPosition := rat("",::cFile)
> if nPosition > 0
> cReturn := left(::cFile,nPosition)
> else
> cReturn := curdir()
> if !empty(cReturn)
> cReturn := ""+cReturn
> endif
> cReturn := cReturn+""
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Name() ³
> ³ Description: returns just the name part of cFile, no path no
> extention ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:57:53pm Time updated: í¾12:57:53pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Name()
> local cReturn := ""
> local nPosition := rat("",::cFile)
> if nPosition > 0
> cReturn := substr(::cFile,nPosition+1)
> else
> cReturn := ::cFile
> endi
> nPosition := rat(".",cReturn)
> if nPosition > 0
> cReturn := left(cReturn,nPosition-1)
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Ext() ³
> ³ Description: return the extention from a file name ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:42:13pm Time updated: í¾12:42:13pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Ext()
> local cReturn := ""
> local nPosition := rat(".",::cFile)
> if nPosition > 0
> cReturn := substr(::cFile,nPosition+1)
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Erase() ³
> ³ Description: delete the file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 05:32:34pm Time updated: í¾05:32:34pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Erase()
> local lSuccess := .f.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> ::close()
> endi
> if ::nHandle == nil
> lSuccess := (fErase(::cFile)==0)
> ::FileError(ferror())
> endi
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Rename() ³
> ³ Description: rename the file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 05:43:45pm Time updated: í¾05:43:45pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: cNewName - the new name for the file ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Rename(cNewName)
> local lSuccess := .f.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> ::close()
> endi
> if ::nHandle == nil
> lSuccess := (frename(::cFile,cNewName)==0)
> ::FileError(ferror())
> if lSuccess
> ::cFile := cNewName
> endif
> endi
> return(lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: FileError() ³
> ³ Description: set/get Error number ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 12:30:58pm Time updated: í¾12:30:58pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: nError ³
> ³ Return Value: nError ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method FileError(nError)
> if pcount() > 0
> ::nError := nError
> if nError > 0
> alert("File Error for:;"+::cfile+";"+::whatswrong())
> if ::ErrorBreak()
> break
> endif
> endi
> endif
> return(::nError)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: WhatsWrong() ³
> ³ Description: Tell what the error is ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 11:20:46am Time updated: í¾11:20:46am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cError - error string ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method WhatsWrong(nError)
> local cError := "UnKnown"
> local aError := {;
> {0 ,"Successful"},;
> {2 ,"File not found"},;
> {3 ,"Path not found"},;
> {4 ,"Too many files open"},;
> {5 ,"Access denied"},;
> {6 ,"Invalid handle"},;
> {8 ,"Insufficient memory"},;
> {15,"Invalid drive specified"},;
> {19,"Attempted to write to a write-protected disk"},;
> {21,"Drive not ready"},;
> {23,"Data CRC error"},;
> {29,"Write fault"},;
> {30,"Read fault"},;
> {32,"Sharing violation"},;
> {33,"Lock Violation"}}
> default nError to ::nError
> if (nError := ascan(aError,{|ele| ele[1] == nError })) > 0
> cError := aError[nError,2]
> endif
> return(cError)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ErrorBreak() ³
> ³ Description: get/set for error break variable ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 12:46:19pm Time updated: í¾12:46:19pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: lBreak ³
> ³ Return Value: ::lBreak ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method ErrorBreak(lBreak)
> if pcount() > 0
> ::lBreak := lBreak
> endif
> return(::lBreak)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: SaveTo() ³
> ³ Description: save the file to somewhere ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 01/20/06 Date updated: í¾01/20/06 ³
> ³ Time created: 11:34:05pm Time updated: í¾11:34:05pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: Self ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method SaveTo()
> local cFileName
> local aFilter := {{"CSV Files","*.csv"},{"All Files","*.*"}}
>
> cFileName := getsavefilename(;
> getactivewindow(),; // hWnd:
> ::Name()+"."+::Ext(),; // cFile:
> "Save Processed Data",; // cTitle:
> aFilter,; // aFilter:
> OFN_EXPLORER+OFN_NOCHANGEDIR,; // nFlags:
> ::Path(),; // cInitDir:
> "csv",; // cDefExt:
> 1) // nIndex:
>
> if !empty(cFileName)
> ::rename(cFileName)
> endif
> return(::cFile)
>
> DGauss wrote:
>>>> There are a lot of ways to do it. You can use MemoWrit,
>>>> FOpen/FWrite, etc.
>>
>> it depends on your needs. If you explain what want to achieve we can help
>>
>> you better.<<
>>
>> I was hoping for a generic class or the use of FileSystemObject from the
>> Windows scripting api.
>> In fact, just SET PRINTER TO is working fine in my code, in
>> combination with
>> '?' statements. It just seems unnatural at this point, i.e. a file class
>> would seem more natural and generic.
>>
>>
>>
just:
// writing
oFile := fileio():new("c:somepathwritefile.txt")
oFile:writesome("this is a line")
oFile:close()
// reading
oFile := fileio():new("c:somepathreadfile.txt")
cLine := oFile:readsome()
oFile:close()
automatically handles creation/opening and closing (when needed) and
file handles for you.
with many options
dan
user@domain.invalid wrote:
> here is a fileio class that i like to use
>
>
> /*í‰í Program
> íííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí íííí»
> º Application: Program/Class Development º
> º Description: file class º
> º File Name: FILEIO.PRG º
> º Author: L. M. Skousen º
> º Date created: 03-19-02 Date updated: í¾03-19-02 º
> º Time created: 05:15:15pm Time updated: í¾05:15:15pm º
> º Make File: MAKEFILE º
> º Exec File: .exe Docs By: L. M. Skousen º
>
> í‡í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„¶
>
> º Revisions: º
> º º
>
> íˆííííííííííííííííííííííííííííí íííííííííííííííííííííííííííííí ííííííííííííííí¼
>
> */
>
> // #include "class(y).ch"
> #include "hbclass.ch"
> #include "common.ch"
> #include "fileio.ch"
> // for what32 ::saveto()
> #include "commdlg.ch"
>
>
> create class fileio
> export:
> var nHandle
> var cFile // path and file name and ext
> var nError
> var nAccess
> var nShare
> var nAttribute
> var lBreak
> var nWriteLines // count the number of lines written
>
> method Init
> method GoTop
> method Position
> method GoTo
> method GoBottom
> method Size
> method Ready
> method Open
> method ReadSome
> method WriteSome
> method Close
> method Path
> method Name
> method Ext
> method Exists
> method Erase
> method Rename
> method WhatsWrong
> method FileError
> method ErrorBreak
> method SaveTo
>
> endclass
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: init() ³
> ³ Description: class constructor ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:37:38am Time updated: í¾10:37:38am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: cFileName - path and filename+extention of requested
> file ³
> ³ : nMode - file share and access mode (fileio.ch
> FO_stuff) ³
> ³ Return Value: Self ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Init(cFileName,nMode)
> default cFileName to "Temp.txt"
> default nMode to FO_READWRITE+FO_SHARED
> ::cFile := cFileName
> ::nError := 0
> ::nAttribute := FC_NORMAL
> ::nAccess := nMode%16
> ::nShare := nMode - ::nAccess
> ::lBreak := .f.
> ::nWriteLines := 0
> return (Self)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: gotop() ³
> ³ Description: move pointer position to top of file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:44:10am Time updated: í¾10:44:10am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoTop()
> local lSuccess := .f.
> if ::ready()
> lSuccess := (fseek(::nHandle,0) == 0)
> ::FileError(ferror())
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: position() ³
> ³ Description: give position of file position pointer in bytes ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:58:39am Time updated: í¾10:58:39am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: nReturn - current position of pointer from top of
> file ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Position()
> local nReturn
> if ::ready()
> nReturn := fseek(::nHandle,0,FS_RELATIVE)
> ::FileError(ferror())
> endif
> return (nReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: goto() ³
> ³ Description: move file pointer to a new specified position ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:20:33am Time updated: í¾11:20:33am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: nBytes - number of bytes to move, may be + or - ³
> ³ : [nOrigin] - move is relative to 0-top 1-current
> 2-bottom ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoTo(nBytes,nOrigin)
> local lSuccess := .f.
> default nOrigin to FS_SET
> if ::ready()
> fseek(::nHandle,nBytes,nOrigin)
> lSuccess := (::FileError(ferror()) == 0)
> endi
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: gobottom() ³
> ³ Description: set position of file pointer to bottom of file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:06:38am Time updated: í¾11:06:38am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method GoBottom()
> local lSuccess := .f.
> if ::ready()
> fseek(::nHandle,0,FS_END)
> lSuccess := (::FileError(ferror()) == 0)
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ready() ³
> ³ Description: check if file is ready for operation, if not, open it
> ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:48:22am Time updated: í¾11:48:22am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Ready()
> local lSuccess := .t.
> ::FileError(0)
> if ::nHandle == nil .or. ::nHandle < 0
> ::nHandle := nil
> lSuccess := ::open()
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: open() ³
> ³ Description: open (or create) a file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 10:44:37am Time updated: í¾10:44:37am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: [nMode] - is access and share mode, same as fopen func
> mode³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Open(nMode)
> local lSuccess := .t.
> if !(pcount()==0)
> ::nAccess := nMode%16
> ::nShare := nMode - ::nAccess
> endif
> if !empty(::nHandle)
> ::close()
> endif
> if ! ::exists()
> ::nHandle := fcreate(::cFile,::nAttribute)
> else
> ::nHandle := fopen(::cFile,::nAccess+::nShare)
> endif
> if ::nHandle < 0
> ::FileError(ferror())
> lSuccess := .f.
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: size() ³
> ³ Description: report on file length ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 11:59:57am Time updated: í¾11:59:57am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: size of file in bytes ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Size()
> local nOldPos
> local nReturn
> nOldPos := ::position()
> if ::FileError() == 0 .and. ::gobottom()
> nReturn := ::position()
> if ::FileError() == 0
> ::goto(nOldPos)
> endif
> endif
> return (nReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: writesome() ³
> ³ Description: write to a file additive ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 01:04:05pm Time updated: í¾01:04:05pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: xMessage ³
> ³ : lCRLF - if added carrage return, line feed pair
> wanted ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method WriteSome(xMessage,lCRLF)
> local lSuccess := .f.
> default lCRLF to .t.
> if ::ready()
> if valtype(xMessage) == "A"
> lSuccess := .t.
> aeval(xMessage,{|ele| lSuccess := lSuccess .and.
> ::writesome(ele,lCRLF)})
> else
> ::gobottom()
> if !(lSuccess :=
> (fwrite(::nHandle,xMessage+if(lCRLF,(::nWriteLines++,chr(13) +chr(10)), ""))>0))
>
> ::FileError(ferror())
> endi
> endif
> endi
> return(lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ReadSome() ³
> ³ Description: read from a file from current position ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:31:14pm Time updated: í¾12:31:14pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: xUntil - delimiter str look for or number of bytes
> ³
> ³ Arguments: lForward - true(default)=forward, false=backward ³
> ³ Return Value: cReturn - read part ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method ReadSome(xUntil,lForward)
> local cReturn := ""
> local cBuffer
> local nCount := 0
> local nRead
> local nPosition
> default xUntil to (chr(13)+chr(10))
> default lForward to .t.
> if ::ready()
> do case
> case valtype(xUntil) == "C" // delimit character/str
> do while nCount < 65536 .and. len(cReturn) == nCount
> cBuffer := ::readsome(1024,lForward)
> nCount := nCount+1024
> if lForward
> nPosition := at(xUntil,cBuffer)
> else // lBackward
> nPosition := rat(xUntil,cBuffer)
> endif
> if nPosition > 0
> if lForward
> cReturn := cReturn+left(cBuffer,nPosition+len(xUntil)-1)
> ::goto((nPosition+len(xUntil)-1)-len(cBuffer),FS_RELATIVE)
> else // lBackward
> cReturn := substr(cBuffer,nPosition)+cReturn
> ::goto(nPosition-1,FS_RELATIVE)
> endi
> else
> if lForward
> cReturn := cReturn+cBuffer
> else // lBackward
> cReturn := cBuffer+cReturn
> endi
> endif
> enddo
> case valtype(xUntil) == "N" // number of bytes
> cBuffer := space(xUntil)
> if !lForward // backwards
> nPosition := ::position()
> xUntil := min(xUntil,nPosition)
> ::goto(nPosition-xUntil)
> endif
> nRead := fread(::nHandle,@cBuffer,xUntil)
> cReturn := left(cBuffer,nRead)
> if !lForward // backwards
> ::goto(nPosition-xUntil)
> endif
> endc
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: close() ³
> ³ Description: close a file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:21:53pm Time updated: í¾12:21:53pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Close()
> local lSuccess := .t.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> lSuccess := !fclose(::nHandle)
> ::nHandle := nil
> ::FileError(ferror())
> endif
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: exists() ³
> ³ Description: check if file exists ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:19:14pm Time updated: í¾12:19:14pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: file(::cFile) true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Exists()
> return (file(::cFile))
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Path() ³
> ³ Description: returns the path of cFile ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:45:00pm Time updated: í¾12:45:00pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Path()
> local cReturn := ""
> local nPosition := rat("",::cFile)
> if nPosition > 0
> cReturn := left(::cFile,nPosition)
> else
> cReturn := curdir()
> if !empty(cReturn)
> cReturn := ""+cReturn
> endif
> cReturn := cReturn+""
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Name() ³
> ³ Description: returns just the name part of cFile, no path no
> extention ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:57:53pm Time updated: í¾12:57:53pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Name()
> local cReturn := ""
> local nPosition := rat("",::cFile)
> if nPosition > 0
> cReturn := substr(::cFile,nPosition+1)
> else
> cReturn := ::cFile
> endi
> nPosition := rat(".",cReturn)
> if nPosition > 0
> cReturn := left(cReturn,nPosition-1)
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Ext() ³
> ³ Description: return the extention from a file name ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 12:42:13pm Time updated: í¾12:42:13pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cReturn ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Ext()
> local cReturn := ""
> local nPosition := rat(".",::cFile)
> if nPosition > 0
> cReturn := substr(::cFile,nPosition+1)
> endif
> return (cReturn)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Erase() ³
> ³ Description: delete the file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 05:32:34pm Time updated: í¾05:32:34pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Erase()
> local lSuccess := .f.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> ::close()
> endi
> if ::nHandle == nil
> lSuccess := (fErase(::cFile)==0)
> ::FileError(ferror())
> endi
> return (lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: Rename() ³
> ³ Description: rename the file ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03-20-02 Date updated: í¾03-20-02 ³
> ³ Time created: 05:43:45pm Time updated: í¾05:43:45pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: cNewName - the new name for the file ³
> ³ Return Value: lSuccess - true or false ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method Rename(cNewName)
> local lSuccess := .f.
> if !(::nHandle==nil) .and. ::nHandle >= 0
> ::close()
> endi
> if ::nHandle == nil
> lSuccess := (frename(::cFile,cNewName)==0)
> ::FileError(ferror())
> if lSuccess
> ::cFile := cNewName
> endif
> endi
> return(lSuccess)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: FileError() ³
> ³ Description: set/get Error number ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 12:30:58pm Time updated: í¾12:30:58pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: nError ³
> ³ Return Value: nError ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method FileError(nError)
> if pcount() > 0
> ::nError := nError
> if nError > 0
> alert("File Error for:;"+::cfile+";"+::whatswrong())
> if ::ErrorBreak()
> break
> endif
> endi
> endif
> return(::nError)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: WhatsWrong() ³
> ³ Description: Tell what the error is ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 11:20:46am Time updated: í¾11:20:46am ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: cError - error string ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method WhatsWrong(nError)
> local cError := "UnKnown"
> local aError := {;
> {0 ,"Successful"},;
> {2 ,"File not found"},;
> {3 ,"Path not found"},;
> {4 ,"Too many files open"},;
> {5 ,"Access denied"},;
> {6 ,"Invalid handle"},;
> {8 ,"Insufficient memory"},;
> {15,"Invalid drive specified"},;
> {19,"Attempted to write to a write-protected disk"},;
> {21,"Drive not ready"},;
> {23,"Data CRC error"},;
> {29,"Write fault"},;
> {30,"Read fault"},;
> {32,"Sharing violation"},;
> {33,"Lock Violation"}}
> default nError to ::nError
> if (nError := ascan(aError,{|ele| ele[1] == nError })) > 0
> cError := aError[nError,2]
> endif
> return(cError)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: ErrorBreak() ³
> ³ Description: get/set for error break variable ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 03/24/04 Date updated: í¾03/24/04 ³
> ³ Time created: 12:46:19pm Time updated: í¾12:46:19pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: lBreak ³
> ³ Return Value: ::lBreak ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method ErrorBreak(lBreak)
> if pcount() > 0
> ::lBreak := lBreak
> endif
> return(::lBreak)
>
> /*íší„ Method
> í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„¿
> ³ Name: SaveTo() ³
> ³ Description: save the file to somewhere ³
> ³ Author: L. M. Skousen ³
> ³ Date created: 01/20/06 Date updated: í¾01/20/06 ³
> ³ Time created: 11:34:05pm Time updated: í¾11:34:05pm ³
>
> íƒí„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„´
>
> ³ Arguments: None ³
> ³ Return Value: Self ³
>
> í€í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„ í„í„í„í„í„í„í„í„í„í„í„í„í„í„í„í™
>
> */
> method SaveTo()
> local cFileName
> local aFilter := {{"CSV Files","*.csv"},{"All Files","*.*"}}
>
> cFileName := getsavefilename(;
> getactivewindow(),; // hWnd:
> ::Name()+"."+::Ext(),; // cFile:
> "Save Processed Data",; // cTitle:
> aFilter,; // aFilter:
> OFN_EXPLORER+OFN_NOCHANGEDIR,; // nFlags:
> ::Path(),; // cInitDir:
> "csv",; // cDefExt:
> 1) // nIndex:
>
> if !empty(cFileName)
> ::rename(cFileName)
> endif
> return(::cFile)
>
> DGauss wrote:
>>>> There are a lot of ways to do it. You can use MemoWrit,
>>>> FOpen/FWrite, etc.
>>
>> it depends on your needs. If you explain what want to achieve we can help
>>
>> you better.<<
>>
>> I was hoping for a generic class or the use of FileSystemObject from the
>> Windows scripting api.
>> In fact, just SET PRINTER TO is working fine in my code, in
>> combination with
>> '?' statements. It just seems unnatural at this point, i.e. a file class
>> would seem more natural and generic.
>>
>>
>>