Find or enumerate files

Syntax

lpstr dir([file] [flags])

 

Parts

file - file or folder. Also can be drive (QM 2.1.9.1).

flags: 0 (default) - find only files; 1 - find only folders and drives; 2 - find all. If dir is used without arguments, or flags is 3, uses previous flags.

 

Remarks

When to use:

1. To test file or folder existence;

2. To enumerate files and folders.

 

If file exists, dir returns filename with extension. Otherwise it returns 0.

 

file can be full path, or filename in current directory, or path relative to current directory. Filename can contain wildcard characters. If file is omitted or "", finds next file that matches file with wilcard characters from previous call (in current function).

 

To get more information about a file, use functions of class Dir, or other functions, such as GetFileInfo, GetAttr. Class Dir also can be used to enumerate files. To insert code, use "Get file info" or "Enumerate files" dialog.

 

See also: searchpath, iff, special folders

 

Examples

 If file exists ...:
if(dir("$desktop$\test.txt"))
	out "file exists"

 Files in desktop folder:
lpstr s=dir("$desktop$\*.*")
rep
	if(s = 0) break
	out s
	s = dir

 Folders in c:\windows:
lpstr s=dir("c:\windows\*" 1)
rep
	if(s = 0) break
	out s
	s = dir("" 1)

 Drives:
Wsh.FileSystemObject fso._create
Wsh.Drive dr
foreach dr fso.Drives
	out dr.Path
	out dr.DriveType ;;0 unknown, 1 removable, 2 fixed, 3 network, 4 CD-ROM, 5 RAM disk