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 15:24, 22 April 2007 (edit)
Woody (Talk | contribs)

← Previous diff
Revision as of 14:11, 26 April 2007 (edit) (undo)
Sandman (Talk | contribs)

Next diff →
Line 3: Line 3:
==Definition== ==Definition==
 +'''INT''' glob ( <'''STRING''' criteria> )
-'''INT''' glob ( <'''STRING''' directory> )+Gets a single filename 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.+
- +
== 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 || - Search criteria: the folder in which you want to look, as well as any simple requirements for filenames such as extensions.
|} |}
- 
== Returns == == Returns ==
- +'''STRING''' : Filename
-'''STRING''' : Returns the filename of the found file, or an empty string if it couldn't find anything.+{|
 +| "" || - No (new) file entries.
 +|-
 +| !"" || - The filename of a file entry matching the search criteria.
 +|}
== 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 method result in the same, but the second one is less code.

Revision as of 14:11, 26 April 2007


Contents

Definition

INT glob ( <STRING criteria> )

Gets a single filename 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.

Parameters

STRING criteria - Search criteria: the folder in which you want to look, as well as any simple requirements for filenames such as extensions.

Returns

STRING : Filename

"" - No (new) file entries.
 !"" - The filename of a file entry matching the search criteria.

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 method result in the same, but the second one is less code.

Personal tools