FILES (new)
Jump to navigation
Jump to search
![]() |
![]() |
![]() |
![]() |
Description
- You can retrieve information about files on disk with the Files statement.
Syntax
- FILES #handle, pathStringExpr$ - Create a file accessor object for accessing files at pathStringExpr$
Hints
- The pathStringExpr$ contains drive and path information. It can also contain file information, including wildcards. Some possible files statements:
files #m, DefaultDir$ files #n, DefaultDir$ + "\*.*" files #p, "C:\RBP\*.txt"
File Accessor Methods
- DATE$()
- DATEFORMAT()
- DEBUG$()
- HASANSWER()
- ISDIR()
- ISNULL()
- NAME$()
- NEXTFILE$()
- RESET()
- ROWCOUNT()
- SIZE()
- TIME$()
- TIMEFORMAT()
Example
The following demo finds all files in the DefaultDir$ in a loop. It prints information about each file.
files #f, DefaultDir$ + "\*.*" print "hasanswer: ";#f HASANSWER() print "rowcount: ";#f ROWCOUNT() print " " :print " " 'set format of file date to template given #f DATEFORMAT("mm/dd/yy") 'set format of file time to template given #f TIMEFORMAT("hh:mm:ss") count = #f rowcount() for i = 1 to count if #f hasanswer() then 'print nextfile info in default format: 'print "nextfile: ";#f NEXTFILE$() 'set the delimiter for nextfile info print "nextfile info: ";#f nextfile$(" ") print "name: ";#f NAME$() print "size: ";#f SIZE() print "date: ";#f DATE$() print "time: ";#f TIME$() print "isdir: ";#f ISDIR() print " " 'blank line end if next
The next demo looks for jpg files, and if any are found, it prints the file names.
files #g, DefaultDir$ + "\*.jpg" if #g HASANSWER() then count = #g rowcount() for i = 1 to count if #g hasanswer() then 'retrieve info for next file #g nextfile$() 'print name of file print #g NAME$() end if next end if wait
Another example not requiring a row count and outputs file date and time from one statement. This example also uses the IsNull() method and the Debug() method to print out the type of object, in this case it is "Files".
print "Before creation, IsNull() returns:" print #f isnull() files #f, DefaultDir$ + "\*.*" while #f hasanswer() #f nextfile$() fileData$ = #f name$();" - "; #f date$();" - "; #f time$() print fileData$ wend print print """";#f debug$();""" is the type of object for #f" print print "After creation, IsNull() returns:" print #f isnull() wait
Useful Procedures
' Place a useful function or sub using this keyword here