Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
This is a nice little function that’s been mostly superseded by later additions to the language. It returns the name of a file matching a skeleton. You can use it in a loop to find all files that match a given skeleton.
cFileName = SYS( 2000, cSkeleton [ ,1 ] )
Parameter |
Value |
Meaning |
cSkeleton |
Character |
A file specification. It can contain the DOS wildcards "?" and "*". |
1 |
Included |
Find the next matching file. |
Omitted |
Find the first matching file. |
The order in which filenames are returned is the order they appear in a DOS DIR listing. Of course, this is a pretty useless order. ADIR()
, which is generally a better choice than SYS(2000), also uses the DOS order, but you can then ASORT()
to get some useful order. The only situation where we’ve found a use for the SYS(2000) function is one where we are polling a directory for the next file matching a skeleton, grabbing it for processing, and immediately deleting or renaming it. Multiple machines can poll the same directory, and each will get the name of the next file in queue. Grabbing the first available name is faster than searching an entire directory listing, particularly on slower hardware.
* Our own version of ADIR() - no reason to use it
* Assume cSkel is the file skeleton
LOCAL nFileCount, cFileName, aFiles[1]
cFileName=SYS(2000,cSkel)
nFileCount=0
DO WHILE NOT EMPTY(cFileName)
nFileCount = nFileCount + 1
DIMENSION aFiles[nFileCount]
aFiles[nFileCount] = cFileName
cFileName = SYS(2000,cSkel,1)
ENDDO