DIR

Action

Dir can be used to enumerate the files in a directory. Dir returns a string representing the name of a file, directory, or folder that matches a specified pattern. To retrieve subsequent entries in a directory, specify an empty string ("") as the path.

 

Syntax

DIR ("path", index)

 

Parameter

Path

Optional string that specifies a file name — may include directory or folder, and drive. If  path is empty (""), Dir will return the next file of the previously opened enumeration handle. Wildcards (‘*’ and ‘?’) are supported.

Index

Optional number indicating which enumeration handle to use. The Dir function can enumerate two directories at the same time. To open the second enumeration handle, specify 1 for the index.

Returns

 

Returns a string representing the name of a file, directory, or folder that matches a specified pattern. An empty string ("") is returned if path is not found or to indicate that the end of the current enumeration was reached. Dir also sets the value of @ERROR :

0

Dir successful.

Error code

Function failed.

 

Example

$FileName = Dir("C:\TEMP\*.*")

While $FileName <> "" and @ERROR = 0

    ? $FileName

    $FileName = Dir()  ; retrieve next file

Loop