DirectoryEntryType()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Thomas
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Apr 26, 2003 8:45 pm

DirectoryEntryType()

Post by Thomas »

The command ExamineDirectory() normally works as designed. But I have written a procedure which recursively goes through the filesystem. When the NextDirectoryEntry() command gets the next element and it's a symbolic link, the DirectoryEntryType() command treats it like a directory. Maybe it's not really a bug but symbolic links should not be treated as directories. A new type #PB_DirectoryEntry_Link should do the trick.

Code: Select all

Procedure recursive(dir,path.s,files)
  While NextDirectoryEntry(dir)
    If DirectoryEntryType(dir)=#PB_DirectoryEntry_Directory
      If DirectoryEntryName(dir)<>"." And DirectoryEntryName(dir)<>".."
        If ExamineDirectory(dir+1,path+DirectoryEntryName(dir),"")
          files=files+recursive(dir+1,path+DirectoryEntryName(dir)+"\",0)
          FinishDirectory(dir+1)
        Else
          Debug "error for "+path+DirectoryEntryName(dir)
        EndIf
      EndIf
    Else
      files=files+1
    EndIf
  Wend
  ProcedureReturn files
EndProcedure

ExamineDirectory(1,"C:\","")
Debug Str(recursive(1,"C:\",0))+" files in the filesystem"