Re: Help needed with walk_dir()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello Hacker,

I believe you need dir() more than walk_dir().

Walk_dir() is used more for serching in all sub-directories of a folder or drive.


Syntax: include file.e x = dir(st)

Description: Return directory information for the file or directory named by st. If there is no file or directory with this name then -1 is returned. On Windows and DOS st can contain * and ? wildcards to select multiple files.

This information is similar to what you would get from the DOS DIR command. A sequence is returned where each element is a

sequence that describes one file or subdirectory.

If st names a directory you may have entries for "." and "..", just as with the DOS DIR command. If st names a file then x will have just one entry, i.e. length(x) will be 1. If st contains wildcards you may have multiple entries.

Each entry contains the name, attributes and file size as well as the year, month, day, hour, minute and second of the last

modification. You can refer to the elements of an entry with the following constants defined in file.e:

global constant D_NAME = 1, D_ATTRIBUTES = 2, D_SIZE = 3,

D_YEAR = 4, D_MONTH = 5, D_DAY = 6,

D_HOUR = 7,

D_MINUTE = 8, D_SECOND = 9

The attributes element is a string sequence containing characters chosen from:

'd' directory 'r' read only file 'h' hidden file 's' system file 'v' volume-id entry 'a' archive file

A normal file without special attributes would just have an empty

string, "", in this field.

Comments: The top level directory, e.g. c:\ does not have "." or ".." entries.

This function is often used just to test if a file or directory exists.

Under WIN32, st can have a long file or directory name anywhere in the path.

Under Linux, the only attribute currently available is 'd'.

DOS32: The file name returned in D_NAME will be a standard DOS

8.3 name. (See Archive Web page for a better solution).

WIN32: The file name returned in D_NAME will be a long file name.

Example:

d = dir(current_dir())

d might have: { {".", "d", 0 1994, 1, 18, 9, 30, 02}, {"..", "d", 0 1994, 1, 18, 9, 20, 14}, {"fred", "ra", 2350, 1994, 1, 22, 17, 22, 40}, {"sub", "d" , 0, 1993, 9, 20, 8, 50, 12}

}

d[3][D_NAME] would be "fred"

Example Programs: bin\search.ex, bin\install.ex

See Also: wildcard_file, current_dir, open


Copied from F1 Jockey by Dan Everingham.

Don Cole

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu