- This wiki is out of date, use the continuation of this wiki instead
Glob
From FenixWiki
(Difference between revisions)
Revision as of 15:24, 22 April 2007 (edit) Woody (Talk | contribs) ← Previous diff |
Current revision (00:54, 26 December 2007) (edit) (undo) Sandman (Talk | contribs) m |
||
(5 intermediate revisions not shown.) | |||
Line 3: | Line 3: | ||
==Definition== | ==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. | |
- | + | ||
- | Gets a single filename | + | |
+ | After a call to glob(), the global struct [[fileinfo]] is filled with information about the last file/directory entry returned. | ||
== Parameters == | == Parameters == | ||
- | |||
{| | {| | ||
- | | '''STRING''' | + | | '''STRING''' criteria || - The search criteria to which the returned filenames apply. |
|} | |} | ||
- | |||
== Returns == | == Returns == | ||
+ | '''STRING''' : Filename or directoryname | ||
+ | {| | ||
+ | | "" || - No (new) file/directory entries. | ||
+ | |- | ||
+ | | !"" || - The name of a file/directory entry matching the search criteria. | ||
+ | |} | ||
- | + | == 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: | ||
+ | {| | ||
+ | | <code>*</code> || - Returns the filename of any file/directory in the current directory. | ||
+ | |- | ||
+ | | <code>*.dat</code> || - Returns the filename of any file/directory with extension <code>.dat</code> in the current directory. | ||
+ | |- | ||
+ | | <code>MyDir\*</code> || - Returns the filename of any file/directory in <code>MyDir\</code> relative to the current directory. | ||
+ | |- | ||
+ | | <code>C:\Program Files\*</code> || - Returns the filename of any file/directory in <code>C:\Program Files\*</code>. | ||
+ | |} | ||
== Example == | == Example == | ||
- | |||
<pre> | <pre> | ||
- | + | 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 | ||
</pre> | </pre> | ||
+ | Both methods result in the same, but the second one is less code. |
Current revision
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.