Jim Jim -3 years ago 200
PHP Question

Pascal isDir function

I want to make a program that lists files contained in a certain directory. I want to list the file and only the file, not the folders that is on this directory, too. How can I do this in Pascal? If in PHP, there is a function named "isDir", which return true if the parameter specified is a directory(folder). Using this function, I could check whether the "path" I'm using is a file or a folder.

Now, I am using the FindFirst and FindNext procedure to get all files/folders in the directory.

program mine;
uses dos;

var F: SearchRec
while DosError=0 do begin

Answer Source

Try the following

while DosError=0 do begin
        if ((F.attr and faDirectory) <> faDirectory)
         then  writeln(F.Name);

Sorry my Pascal is a bit rusty

Basically the object returned by FindFirst/FindNext contains an ATTR property which indicated the type of file it is.

Also, at the end of your loop, be sure to add a FindClose() call to free the memory


File attribute constants

  • faDirectory-Is directory
  • faReadOnly-Readonly file
  • faArchive-Archive bit
  • faHidden-File is hidden
  • faVolumeId-File is the volumne ID
  • faSysFile-System File
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download