contents   index   previous   next



SElib.directory()

syntax:

SElib.directory([filespec[, subdirs[,

                 includeAttr[, requireAttr]]]])

where:

filespec - string specification for files to find. The specification must be consistent with the operating system being used and may include wildcard characters. A file specification may include path specifications, both full and partial.

 

subdirs - a boolean as to whether or not to include subdirectories in file search. The default is false, which limits the search for filespec to the current directory.

 

includeAttr - specify the file attributes to include in the file search. Only files with one of the attributes specified will be included in the array of file names and information retrieved. Attribute flags that do not apply to an operating system are ignored. If includeAttr is 0, only files with no attributes are included. The default value is:

 

FATTR_RDONLY|FATTR_SUBDIR|

FATTR_ARCHIVE|FATTR_NORMAL

 

File attributes are set using the following values:

 

FATTR_RDONLY   Read-only file

FATTR_HIDDEN   Hidden file

FATTR_SYSTEM   System file

FATTR_SUBDIR   Directory

FATTR_ARCHIVE  Archive file

 

More than one file attribute can be specified by using the bitwise or operator, "|". For example, to find files with the hidden or system attributes set, use the following expression:

 

FATTR_HIDDEN | FATTR_SYSTEM

 

A file attribute may be excluded from array of files returned by using the bitwise not operator, "~". For example, to exclude subdirectories, use the following expression:

 

~FATTR_SUBDIR

 

requireAttr - specify attributes that files are required to have to be included in the array of file names and information retrieved. Files must have at least these attributes. The difference between the two file attributes specifications is that files must have at least one of the attributes specified by includeAttr but must have all the attributes specified by requireAttr. The default value is 0.

 

return:

array - an array of objects with information about the file names retrieved. If no files or directories match the specifications of the parameters, a null is returned. Each element of the array has the following properties:

 

.name    Full file name, including filespec path.

.attrib  File flags, as defined in IncAttr, number.

.size    Size of file, number in bytes, number.

.access  Date and time of last file access, number.

.write   Date and time of last write, number.

.create  Date and time of file creation, number.

 

For example, if you use the following line of code:

 

var FileList = SElib.directory("*.*");

 

The information for the first file retrieved is accessed using:

 

FileList[0].name

FileList[0].attrib

FileList[0].size

FileList[0].access

FileList[0].write

FileList[0].create

 

The information for the second file is accessed using:

 

FileList[1].name

...

description:

Find files in a directory

 

or subtree that match path and file specifications and have specified file attributes set. Remember the directory names are treated like file names and have the FATTR_SUBDIR attribute set. Matching files and information about them are retrieved and returned in an array of objects. These objects are also structures.

 

This method may be used in many ways. One way, besides the obvious way of getting information about files, is to test for the existence of a file or file specification. If the file specified does not exist, the return is null.

 

see:

SElib.fullpath(), SElib.splitFilename(), File object in fileobj.jsh

 

example:

   // The following routine lists

   // all files matching FileSpec,

   // except subdirectory entries,

   // in the current directory of a script.

function ListDirectory(FileSpec)

{

   var FileList = SElib.directory(FileSpec, False,

      ~FATTR_SUBDIR)

   if (null == FileList)

      Clib.printf(

        "No files found for search spec \"%s\".\n",

        FileSpec)

   else

   {

      var FileCount = getArrayLength(FileList);

      for (var i = 0; i < FileCount; i++)

         Clib.printf(

          "%s\tsize = %d\tCreate date/time = %s\n",

          FileList[i].name, FileList[i].size,

          Clib.ctime(FileList[i].Create));

   }

}

 


SElib.doWindows()