DirTree
System function.
The DirTree function puts file names and directory names into arrays.
Usage
In an automation task, you often have to repeat the same actions for all the files within a directory, or for all the files with a specific extension. DirTree function gives the needed list of files to process. Look at a script example Process and Rename all the files with a specific extension.
Syntax
DirTree(<file_spec$>,tablongname$(),tabshortname$(),tabpath$(),tabattrib$(),"options")
or
ret=DirTree(<file_spec$>,tablongname$(),tabshortname$(),tabpath$(),tabattrib$(),"options")Parameters
<file_spec$>: string such as "c:\mydir\*.txt" or "\\serv\home\dir 1\as??.*", list of files to put in a array. If the path is omitted, the search is performed in the current directory. If option "R" is specified, the files are searched in the current directory and all its subdirectories.
Tablongname$(), tabshortname$(), tabpath$(), tabattrib$() are result arrays. They must have been declared at the beginning of the script with the DIM statement.
Tablongname$() returns the long file names of the files found (including hidden or system files), without their paths.
Tabshortname$() returns the short file names (DOS 8.3 format) of the files found without their paths.
Tabpath$() returns the path (without the \ at the end) of the files found.
Tabattrib$() returns the attributes of the files found:
R
read only
H
hidden
A
archive
S
system
"options" is a string, modifying the search and sort order of the arrays. It may contain one or more of the following letters:
N
sort by name
S
sort by size
E
sort by type (extension)
D
sort by date
R
include subdirectories
A
sort by last access date (this is different from last modification date)
Ex : if option = "AN", the list will be sorted by last access date. For identical access dates, files will be sorted by name.
Return value
ret, integer, number of files found. If no items are found, 0 is returned. If an error is detected in an argument (for instance, an invalid path), a return code of -1 is returned ; unless #IgnoreErrors=1, all the scripts are stopped.
See also
Example
With such a tree :
ivodbc
header
odbcinst.h
sql.h
sqlext.h
sqltypes.h
sqlucode.h
jdbcodbc
brdgread.me
jsjob.exe
msjob.exe
oleodbc
msdadll.exe
msdahelp.exe
msdainst.bat
regsvr32.exe
translat
libmain.c
readme.trn
translat.c
winnt.mak
ivsetup.inf
prodlist.ini
qprofile.dll
read.me
uninst.isu
Statement
ret=Dirtree("c:\ivodbc\*.*",tablong$(),tabshort$(),tabpath$(),tabattrib$(),"GR")
returns 25 and arrays have contents as below :
tablong$()
tabshort$()
tabpath$()
tabattrib$()
header
header
c:\ivodbc
D
jdbcodbc
jdbcodbc
c:\ivodbc
D
oleodbc
oleodbc
c:\ivodbc
D
translat
translat
c:\ivodbc
D
ivsetup.inf
ivsetup.inf
c:\ivodbc
A
prodlist.ini
prodlist.ini
c:\ivodbc
A
qprofile.dll
qprofile.dll
c:\ivodbc
A
read.me
read.me
c:\ivodbc
A
uninst.isu
uninst.isu
c:\ivodbc
A
odbcinst.h
odbcinst.h
c:\ivodbc
A
........