This wiki is out of date, use the continuation of this wiki instead

Glob

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 09:01, 22 April 2007 (edit)
63.138.247.2 (Talk)

← Previous diff
Current revision (00:54, 26 December 2007) (edit) (undo)
Sandman (Talk | contribs)
m
 
(7 intermediate revisions not shown.)
Line 1: Line 1:
[[Category:functions]] [[Category:functions]]
 +[[Category:files]]
==Definition== ==Definition==
 +'''STRING''' glob ( <'''STRING''' criteria> )
-'''INT''' glob ( <'''STRING''' directory> )+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 from the directory specified and keeps returning new ones on subsequent calls until it can't find any more.+
 +After a call to glob(), the global struct [[fileinfo]] is filled with information about the last file/directory entry returned.
== Parameters == == Parameters ==
- 
{| {|
-| '''STRING''' directory || - The folder in which you want to look, as well as any simple requirements for filenames such as extensions.+| '''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.
 +|}
-'''STRING''' : Returns the filename of the found file, or an empty string I think.+== 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>
-BEGIN+Program files;
 +Private
 + String filename;
 +Begin
- LOOP+ // 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
- string1=GLOB("levels\*.tul"); //looks for a file in the relative folder "levels" that has the file extension "tul".+ End
- IF (string1<>"")+
- alllevels[z]=string1;+
- z++;+
- ELSE+
- numberlevels=z;+
- BREAK;+
- END+
- END+ // method two:
-END+ 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.

Personal tools