ReadDirectory

Prev Next Home Home Table Of Contents Index

ReadDirectory (Path,Array)

Second Syntax: ReadDirectory (Path,Files,Dirs)

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:
Var X WholeFileNames Off ReadDirectory('*.MNU',X) Loop X Execute ('COPY ' + LoopVal + ' A:') EndLoop

Here's a recursive example where we use ReadDirectory to read all the directories on the current drive.


 StandardIO
 DirectoriesOnly
 WholeFileNames

ReadSubdirectories(CleanFileName('\'))

Procedure ReadSubdirectories (Dir) var Subs Writeln Dir ReadDirectory(Dir,Subs) Loop Subs ReadSubdirectories(LoopVal) EndLoop EndProc

Here's an example of a program written in MarxMenu using ReadDirectory to list all files on and below the current directory.


Example:

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

Second Syntax: ReadDirectory (Path,Files,Dirs)

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:

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

When ReadDirectory is used with separate arrays, the variable WholeDirectoryNames is used to control if the whole directory name from the root is used.

See Also: WholeFileNames HiddenAndSystem IncludeDirectories
DirectoriesOnly ReadSqDirectory ReadLongNames
WholeDirectoryNames

Category: Array Directory LongName

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home