![]() ![]() ![]() ![]() | Table Of Contents | Index |
Reads a directory into an array. This command's behavior is controlled by several variables.
If WholeFileNames is set to true, the names that are returned contain the whole path. If HiddenAndSystem is set to true, then Hidden and System files are also read. If IncludeDirectories is set to true, then directories are also read.
If DirectoriesOnly is set to true, then only directory names are read. If ReadLongNames is set to true, the long file names are read.
Example:Here's a recursive example where we use ReadDirectory to read all the directories on the current drive.
Var X WholeFileNames Off ReadDirectory('*.MNU',X) Loop X Execute ('COPY ' + LoopVal + ' A:') EndLoop
StandardIO DirectoriesOnly WholeFileNamesHere's an example of a program written in MarxMenu using ReadDirectory to list all files on and below the current directory.ReadSubdirectories(CleanFileName('\'))
Procedure ReadSubdirectories (Dir) var Subs Writeln Dir ReadDirectory(Dir,Subs) Loop Subs ReadSubdirectories(LoopVal) EndLoop EndProc
Example:Second Syntax: ReadDirectory (Path,Files,Dirs)
ReadSubdirectories ('.')
Procedure ReadSubdirectories (Dir) var Subs Files
IncludeDirectories Off DirectoriesOnly Off WholeFileNames On
ReadDirectory(Dir,Files)
Loop Files Writeln LoopVal EndLoop Dispose(Files)
IncludeDirectories On DirectoriesOnly On
ReadDirectory(Dir,Subs)
Loop Subs ReadSubdirectories(LoopVal) EndLoop Dispose(Subs) EndProc
ReadDirectory now has a second way to be used. If you pass two array variables, ReadDirectory will read the files into the first array and the directories into the second array.
Here's a rewrite of the above example taking advantage of the new syntax.
Example:When ReadDirectory is used with separate arrays, the variable WholeDirectoryNames is used to control if the whole directory name from the root is used.
ReadSubdirectories ('.')
Procedure ReadSubdirectories (Dir) var Subs Files
WholeFileNames On
ReadDirectory(Dir,Files,Subs)
Loop Files Writeln LoopVal EndLoop Dispose(Files)
Loop Subs ReadSubdirectories(LoopVal) EndLoop Dispose(Subs) EndProc
See Also: | WholeFileNames | HiddenAndSystem | IncludeDirectories |
---|
DirectoriesOnly | ReadSqDirectory | ReadLongNames |
WholeDirectoryNames |
Category: | Array | Directory | LongName |
---|
![]() ![]() ![]() ![]() | Table Of Contents | Index |
|