File Properties / Attributes Functions
FileAttr | Determines a file’s attributes |
FileDate | Determines the file date |
FileSize | Determines the size of a file |
FileTime | Determines a file’s time |
Searches for files by name and attribute and get file properties
Syntax :
FileFindFirst( <cFileNameMask>, @<pFFindInfo>[, <nAttr> ] ) -> <lFound> FileFindNext( <pFFindInfo> ) -> <lFound> FileFindName( <pFFindInfo> ) -> <cFileName> FileFindAttr( <pFFindInfo> ) -> <nAttr> FileFindSize( <pFFindInfo> ) -> <nSize> FileFindDate( <pFFindInfo> ) -> <dDate> FileFindTime( <pFFindInfo> ) -> <cTime>
Arguments
<cFileNameMask> : A file name including its path and drive designation. It may contain wildcards.
<pFFindInfo> : A pointer for an internal data structure to hold file(s) info
<nAttr> : The file attribute that corresponds to the ones described in the table on the next page. The default value is 0.
Coding the File Attribute ---------------------------------------------------------------- Value Symb. constants Assigned attribute ----------- ---------------- ----------------------------------- 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 8 FA_VOLUME VOLUME (Name of a floppy/hard disk) 16 FA_DIRECTORY DIR (Directory) 32 FA_ARCHIVE ARCHIVE (Changes since last backup) ----------------------------------------------------------------
Returns
<lFound> : A logical value indicate file existence
<cFileName> : Name of file found by FileFindFirst() or FileFindNext() (without drive/dir)
<nAttr> : A numeric value indicate attribute info of file
<nSize> : A numeric value indicate size of file
<dDate> : A date value indicate date of file
<cTime> : A character value indicate time of file (as “HH:MM:SS”)
Description
FileFindXxxx functions provides a set of info on a set of file.
Calling first FileFindFirst() build an internal data structure ( probably an array like returned by Directory() ). And then calling other FileFindXxxx functions returns individual file info for last file found.
This function set look like FileSeek() function. For more info look at it.
Note
Internal Data Buffer : Every FileFindXxxx() function uses internal data structure <pFFindInfo>. For further using this variable should be passed by reference in FileFindFirst(). May be useful release this buffer by go out of scope or be explicitly release by freeing <pFFindInfo> variable a way like this:
<pFFindInfo> := NIL
Example
PROC TestFFs() LOCAL pFFInfo LOCAL nFileNo := 0 LOCAL lContinue := FileFindFirst( '*.*', @pFFInfo ) WHIL lContinue ? PAD( ++nFileNo, 3),; PAD( FileFindName( pFFInfo ), 23 ),; FileFindAttr( pFFInfo ),; FileFindSize( pFFInfo ),; FileFindDate( pFFInfo ),; FileFindTime( pFFInfo ) lContinue := FileFindNext( pFFInfo ) END RETU // TestFFs()
Seealso
Directory(), FileSeek(), FileAttr(), FileDate(), FileSize(), FileTime(), HB_FileMatch()
Determines the size of a file
Syntax
FileSize([<cFileMap>, [<FileAttr>]]) --> <nFileSiz>
Arguments
<cFileMap> : Designates the file name, path, and drive designation.
<FileAttr> : Designates the file attribute that is explained in the table below. The default value is 0. () : If the function is called without parameters, it returns the file size from the current FileSeek() buffer.
Returns
<nFileSiz> : a numeric value designated file’s size, the size from the FileSeek() buffer (when called without a parameter), or -1.
Description
Implement FileSize() alone or in conjunction with FileSeek(). If the function is called with the <cFileMap> parameter, it returns the size of the first entry found. If no matching entry is available, then a value of -1 is returned
When called without parameters, FileSize() returns the size of the most recent file found with FileSeek(). Used in conjunction with FileSeek(), you can also determine the size of file groups (wildcards).
You can designate the attribute for the desired file in numeric form:
Coding the File Attribute ---------------------------------------------------------------- Value Symb. constants Assigned attribute ---------------------------------------------------------------- 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 32 FA_ARCHIVE ARCHIVE (Changes since last backup.) ----------------------------------------------------------------
Specify only the SYSTEM, HIDDEN, VOLUME, or DIR attributes for an entry to be found. If multiple attributes are implemented simul-taneously, the table values are added accordingly. Of course, not all combinations are useful.
Examples
. Show the size of a particular file: ? FileSize("C:\TEXT\TEXT.TXT") // File size or -1 . The size of an ARCHIVE/HIDDEN file: ? FileSize("C:\HIDE.TXT", 34") // File size or -1 . Used in conjunction with FileSeek(): cFile := FileSeek(C:\TEXT.TXT") DO WHILE .NOT. EMPTY(cFile) ? cFile, FileSize() // File name and size cFile := FileSeek() // Search for next entry ENDDO
Seealso
Determines the file date
Syntax
FileDate([<cFileMap>, [<nFileAttr>]]) --> <dFileDate>
Arguments
<cFileMap> : Designates a file name, including its path and drive designation. <nFileAttr> : Designates the file attribute explained in the table below. The default value is 0. () If you call this function without parameters, it returns the file date from the current FileSeek() buffer.
Returns
<dFileDate> : the date of the searched for entry, the date from the FileSeek() buffer (when called without parameters), or an empty date.
Description
You can implement FileDate() alone or in conjunction with FileSeek(). If you use the <cFileMap> parameter to call this function, it returns the date of the first entry found. If a suitable entry is not present, an empty date is returned.
When called without parameters, FileDate() returns the date of the last file it located with FileSeek(). You could also determine the dates for a file group (wildcards), when used it in conjunction with FileSeek().
The attribute for the desired file can be specified in numeric form:
Coding the File Attribute --------------------------------------------------------------- Value Symb. constants Assigned attribute --------------------------------------------------------------- 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 16 FA_DIRECTORY DIR (Directory) 32 FA_ARCHIVE ARCHIVE (Changes since last backup) ---------------------------------------------------------------
To find a file, specify only the SYSTEM, HIDDEN, VOLUME, or DIR attributes. If multiple attributes are implemented simultaneously, the table values are added accordingly. Of course, not all combinations are useful.
Examples
. Show the date of a particular file: ? FileDate("C:\TEXT\TEXT.TXT") // The date . The date of an ARCHIVE/HIDDEN file: ? FileDate("C:\HIDE.TXT", 34) // The date . Used in conjunction with FileSeek(): cFile := FileSeek("C:\TEXT\*.TXT") DO WHILE .NOT. EMPTY(cFile) ? cFile, FileDate() // Name & date of file cFile := FileSeek() // Search for next entry ENDDO
Seealso
Determines a file’s attributes
Syntax
FileAttr([<cFile>]) --> <nFileAttr>
Argument
<cFile> : File name, including the path and drive designation.
Returns
<nFileAttr> : a numeric value for file attributes
Description
FileAttr() is implemented alone or in conjunction with FileSeek(). If the function is called with the <cFile> parameter, it returns the attribute of the first entry found. If no acceptable entry is available, a value of 0 is returned.
When called without a parameter, FileAttr() returns the attribute for the most-recent file located with FileSeek(). When used with FileSeek(), you can determine the attribute for file groups (wildcards).
When you call FileAttr() with the <cFile> parameter, the function internally passes 63 (all attributes) as a mask. When used in conjunction with FileSeek(), you should also designate all 63 as an attribute mask, if all files are to be acknowledged.
Coding the File Attribute ------------------------------------------------------------- Value Symb. constants Assigned attribute ------------------------------------------------------------- 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 8 FA_VOLUME VOLUME (Name of a floppy/hard disk) 16 FA_DIRECTORY DIR (Directory) 32 FA_ARCHIVE ARCHIVE (Changes since last backup) ---------------------------------------------------------------
If multiple attributes are implemented for a file, the value of each corresponding attribute is added.
Examples
. Show the attribute of a specific file: ? FileAttr("C:\TEXT\TEXT.TXT") // 32 ARCHIVE . The attribute for an ARCHIVE/HIDDEN file: ? FileAttr("C\HIDE.TXT") // 34 HIDDEN + ARCHIVE . Used in conjunction with FileSeek(): cFile := FileSeek("C:\TEXT\TEXT.TXT") DO WHILE .NOT. EMPTY (cFile) ? cFile, FileAttr() // Name & file attribute cFile := FileSeek() // Search for next entry ENDDO
Seealso
FILEINFO() Short: ------ FILEINFO() Returns file date,time,size Returns: -------- <expInfo> => Returns file date,time or size Syntax: ------- FILEINFO(cFileName,nInfo) Description: ------------ Returns info on file in <cFileName> based on param passed as <nInfo> 1 - returns file size (numeric) 2 - returns file date (date) 3 - returns file time (character) Examples: --------- nFilesize := fileinfo("customer.dbf",1) dFileDate := fileinfo("customer.dbf",2) dFileTime := fileinfo("customer.dbf",3) Source: ------- S_FILEIN.PRG
FILETIME() Determines a file's time ------------------------------------------------------------------------------ Syntax FILETIME([<cFileMap>, [<nFileAttr>]]) --> cFileClockTime Arguments <cFileMap> Designates the file name, including the path and drive designation. <nFileAttr> Designates the file attribute explained in the table below. The default value is 0. () If the function is called without parameters, it returns the file time from the current FILESEEK() buffer. Returns FILETIME() returns the clock time for the "searched for" entry, the clock time from the FILESEEK() buffer (when called without parameters), or a null string. Description Implement FILETIME() alone or in conjunction with FILESEEK(). If the function is called with the <cFileMap> parameter, it returns the time of the first entry found. If no matching entry is available, a null string is returned. When called without parameters, FILETIME() returns the clock time of the last file found with FILESEEK(). You can also determine the clock time of file groups (wildcards) when the function is used in conjunction with FILESEEK(). You can designate the attribute for the desired file in numeric form: Table 7-17: Coding the File Attribute ------------------------------------------------------------------------ Value Symb. constants Assigned attribute ------------------------------------------------------------------------ 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 16 FA_DIRECTORY (Subdirectory) 32 FA_ARCHIVE ARCHIVE (Changes since last backup) ------------------------------------------------------------------------ Only the SYSTEM, HIDDEN, VOLUME, or DIR attributes must be specified for an entry to be found. If multiple attributes are implemented simultaneously, the table values are added accordingly. Of course, not all combinations are useful. Examples . The clock time of a particular file: ? FILETIME("C:\TEXT\TEXT.TXT") // File clock time or "" . The clock time of an ARCHIVE/HIDDEN file: ? FILETIME("C:\HIDE.TXT", 34") // File clock time or "" . Used in conjunction with FILESEEK(): cFile := FILESEEK(C:\TEXT.TXT") DO WHILE .NOT. EMPTY(cFile) ? cFile, FILETIME() // File name and clock time cFile := FILESEEK() // Search for next entry ENDDO
See Also: FILESEEK() FILEATTR() FILEDATE() FILESIZE()
How I can obtain date and time of my application ?
PROC MAIN() * lib : hbct SETMODE( 25, 80 ) CLS SET DATE GERM SET CENT ON ? "Date of this application :", FILEDATE( HB_PROGNAME() ) ? "Time of this application :", FILETIME( HB_PROGNAME() ) ? WAIT "EOF AppDaTim.prg" RETURN // MAIN ( AppDaTim.prg )
Introduction Disk Utilities DELETEFILE() Deletes an error-tolerant file DIRCHANGE() Changes the current directory DIRMAKE() Creates a directory DIRNAME() Determines the name of the current directory DIRREMOVE() Removes a directory DISKCHANGE() Changes the current disk drive DISKCHECK() Creates a checksum for a disk DISKFORMAT() Formats disks, controlled through a UDF DISKFREE() Determines the space available on a floppy or hard disk DISKNAME() Determines the drive designator for the current drive DISKREADY() Tests to see if a disk drive is ready DISKREADYW() Queries whether you can write to a drive DISKSPEED() Determines a comparison value for the drive speed DISKSTAT() Determines the status of a drive. DISKTOTAL() Determines the total capacity of a floppy or hard disk DISKTYPE() Determines the type of data carrier DRIVETYPE() Determines the drive type FILEAPPEND() Appends data to a file FILEATTR() Determines a file's attributes FILECCLOSE() Closes a file after backup mode FILECCONT() Copies sections of a file in backup mode FILECDATI() Determines which date the target file contains with FILECOPY() FILECHECK() Calculates/computes/determines a checksum for a file FILECOPEN() Tests to see if the file is still open in the backup mode FILECOPY() Copies files normally or in backup mode FILEDATE() Determines the file date FILEDELETE() Deletes file(s) by name and attribute FILEMOVE() Moves files to another directory FILESEEK() Searches for files by name and attribute FILESIZE() Determines the size of a file FILESTR() Reads a portion of a file into a string FILETIME() Determines a file's time FILEVALID() Tests whether a string has a valid file name FLOPPYTYPE() Determines the exact type of floppy drive GETSHARE() Determines the file open (share) mode NUMDISKF() Determines the number of installed disk drives NUMDISKH() Determines the number of hard disks NUMDISKL() Determines the number of available logical drives RENAMEFILE() Fault tolerant renaming of a file. RESTFSEEK() Restores the FILESEEK environment SAVEFSEEK() Saves the current FILESEEK environment SETFATTR() Sets a file's attributes SETFCREATE() Default attribute for creating with CA-Clipper Tools functions SETFDATI() Sets the date and time of a file SETSHARE() Sets default opening mode for CA-Clipper Tools file functions STRFILE() Writes a string to a file TEMPFILE() Creates a file for temporary use TRUENAME() Standardizes the path designation VOLSERIAL() Determines the DOS disk serial number VOLUME() Establishes a volume label for a floppy or hard disk
Searches for files by name and attribute
Syntax :
FileSeek([<cFileMap>, [<nFileAttr>], [<lExact>]]) --> cFileName
Arguments
<cFileMap> : Designates a file name including its path and drive designation. It may contain wildcards.
<nFileAttr> : Designates the file attribute that corresponds to the ones described in the table on the next page. The default value is 0.
<lExact> : If you designate .T. as the optional parameter, FileSeek() also checks for the exact agreement of the file attributes of the respective file with the value passed by <nFileAttr>.
If you call the function without parameters, it serves as a sequential call for a FileSeek() with file specifications, and returns sequential entries as long as these are found.
Returns
FileSeek() returns the name of the first or next entry (when called without parameter) located in the selected directory.
Description
FileSeek() provides the foundation for a variety of functions. As a group, they permit access to desired information about directory entries. Implement the FileSeek() function when you want information about a file group (wildcards). When you call it with the <cFileMap> parameter, it searches for the first entry in the designated directory. If you call it without parameters, it searches for the next matching entry in the directory. If no more entries are present, it returns a null string. An attribute mask can further define a file group that is being searched for. The desired file attributes are coded as follows:
Table : Coding the File Attribute ------------------------------------------------------------------------ Value Symb. constants Assigned attribute ----------- ---------------- ------------------------------------------- 0 FA_NORMAL 1 FA_READONLY READ ONLY (Read-only) 2 FA_HIDDEN HIDDEN (Hidden files) 4 FA_SYSTEM SYSTEM (System files) 8 FA_VOLUME VOLUME (Name of a floppy/hard disk) 16 FA_DIRECTORY DIR (Directory) 32 FA_ARCHIVE ARCHIVE (Changes since last backup) ------------------------------------------------------------------------
If you implement multiple attributes simultaneously, the table values are added accordingly. Of course, not all combinations are useful.
Exact File Attributes :
DOS does not make an exact comparison with a designated attribute mask and attributes actually found in a file. Specify only the SYSTEM, HIDDEN, VOLUME, or DIR attributes for an entry to be found. Files with only one other attribute bit set are always returned, regardless of the value specified in the attribute mask. This way, a function call with a mask value of 16 returns not only sub-directories, but all files without a set attribute (e.g., all the ARCHIVE and R/O files).
To avoid this, you can designate .T. as the third parameter. The function itself also reviews the designated attribute mask with the actual file attributes, for an exact agreement. Then, the designation of a 16 mask and .T., only returns subdirectories.
Note
Internal Data Buffer :
Every time you use FileSeek() all the data for a directory entry is saved to an internal buffer. Individual information such as size, time, or date is easily accessible. To do this, the FILETIME(), FILEDATE(), etc., functions are called without parameters; otherwise, it requires another call to the disk, instead of taking the data from an internal buffer.
Examples :
- Display the date and size of all files with the extension .TXT in a directory: cFile := FileSeek("C:\TEXT\*.TXT") DO WHILE .NOT. EMPTY(cFile) ? FileSize() // Size of file in buffer ? FileDdat() // Date of file in buffer cFile := FileSeek() // Search for next entry ENDDO - Display system files in the root directory. Attribute: READ ONLY, HIDDEN, SYSTEM, ARCHIVE --> 39, although 6(2 + 4) will suffice as an attribute: cFile := FileSeek("C:\*.*", 39) DO WHILE .NOT. EMPTY(cFile) ? cFile // File name cFile := FileSeek() // Look for next entry ENDDO - Only query the subdirectory: cSubDir := FileSeek("C:\*.*, 16, .T.) DO WHILE .NOT. EMPTY(cSubDir) ? cSubDir // Name of the directory cSubDir := FileSeek() // Search for next directory ENDDO * * - Using FileSeek() as Directory() function PROC FLstFSeek() // File List by FileSeek() LOCAL cFileName,; nFileCount := 0,; nFAttr := 1 +; // ReadOnly 2 +; // Hidden 4 +; // System 16 // Directory ( => 23 ) SET DATE GERM SET CENT ON /* Display system files and directories in the root directory. Attribute: READONLY, HIDDEN, SYSTEM, DIRECTORY --> 23 */ ? PAD( "File Name", 32 ), "Size Date Time Attribute" ? REPL( "-", 32 ), "--------------- ---------- -------- ---------" cFileName := FileSeek("C:\*.*", nFAttr) WHILE .NOT. EMPTY( cFileName ) ++nFileCount ? PAD( cFileName, 32) ,; // File name TRAN( FILESIZE(), "999,999,999,999" ) ,; FILEDATE(),; FILETIME(),; TRAN( FILEATTR(), "99999,999" ) cFileName := FileSeek() // Look for next entry ENDDO ? ? nFileCount, "Files and directories found." ? WAIT "End of FileSeek.prg" RETU // FLstFSeek()
Files
lib : hbct
Seealso
FileAttr(), FileDate(), FileSize(), FileTime(), HB_FileMatch(), Directory()