Find or enumerate files

Syntax

lpstr dir([file] [flags])

 

Parameters

file - file, folder or drive.

flags:

0 Find only files.
1 Find only folders and drives.
2 Find all.
3 If flags is 3 or omitted, uses flags used with dir previously (in current function).

 

Remarks

When to use:

1. To test file or folder existence.

2. To enumerate files and folders.

 

If the file exists, dir returns filename with extension. Else returns 0.

 

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: str.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