- This wiki is out of date, use the continuation of this wiki instead
Glob
From FenixWiki
Contents |
[edit] Definition
STRING glob ( <STRING criteria> )
Gets a single filename or directoryname matching the criteria and keeps returning new ones on subsequent calls until it can't find any more, in which case it returns "". To restart the search, a call to frame() is needed, in which case frame(0); can come in handy.
After a call to glob(), the global struct fileinfo is filled with information about the last file/directory entry returned.
[edit] Parameters
STRING criteria | - The search criteria to which the returned filenames apply. |
[edit] Returns
STRING : Filename or directoryname
"" | - No (new) file/directory entries. |
!"" | - The name of a file/directory entry matching the search criteria. |
[edit] Notes
The search criteria can hold many criteria: the folder in which you want to look, simple requirements for filenames, such as extensions, and directory names. A few examples:
* | - Returns the filename of any file/directory in the current directory. |
*.dat | - Returns the filename of any file/directory with extension .dat in the current directory.
|
MyDir\* | - Returns the filename of any file/directory in MyDir\ relative to the current directory.
|
C:\Program Files\* | - Returns the filename of any file/directory in C:\Program Files\* .
|
[edit] Example
Program files; Private String filename; Begin // method one: Loop filename = Glob("levels\*.tul"); // Looks for a file in the relative folder // "levels" that has the file extension "tul". if(filename!="") load_level(filename); // load_level() would load the level file else Break; end End // method two: While( (filename = Glob("levels\*.tul")) != "" ) load_level(filename); End End
Both methods result in the same, but the second one is less code.