dir()

 
Reads a directory list in path.
Syntax
dir( path, location, entries var )
Returns the number of files found or 0 (zero) if none are found. The parameter entries returns an array of file names found.
  • path = The path to a directory relative to the location
  • location = "data" or "script"
  • entries = array of resultant file names
User Annotations: dir
Ray Yates : mivascript at, pcinet d0t com
09/12/2011 22:19 p.m.
This add-on to the dir() function adds a simple filter for file extensions.
<MvFUNCTION NAME = "Read_Dir" PARAMETERS = "path, ext, loc, filelist var" STANDARDOUTPUTLEVEL = "">
    <MvIF EXPR = "{ dir(l.path, l.loc, l.files) LT 3 }">
        <MvFUNCRETURN VALUE = "">
    </MvIF>
    <MvASSIGN NAME = "l.extlen" VALUE = "{ len(l.ext) }">
    <MvCOMMENT> Ignore ./ and ../ and filter out non matching extensions </MvCOMMENT>
    <MvFOREACH ITERATOR = "l.file" ARRAY = "l.files" INDEX = "l.pos" FIRST = "{ 3 }">
        <MvASSIGN NAME = "l.filelen" VALUE = "{ len(l.file) }">
        <MvIF EXPR = "{ substring(l.file, l.filelen - l.extlen + 1, l.extlen) EQ l.ext }">
            <MvASSIGN NAME = "l.ndx" VALUE = "{ l.ndx + 1 }">
            <MvASSIGN NAME = "l.filelist" INDEX = "{l.ndx}" VALUE = "{ l.file }">
        </MvIF>
    </MvFOREACH>
    <MvFUNCTIONRETURN VALUE = "{ miva_array_collapse(l.filelist) }">
</MvFUNCTION>