Page 1 of 1

ExamineDirectory Results

Posted: Thu Nov 05, 2020 2:52 pm
by collectordave
I am using ExamineDirectory() to look at the home directory returned by GetHomeDirectory().

All is ok but it returns directories that are not shown when using the OpenFileRequester.

A bit of code to test

Code: Select all


Folder.s = GetHomeDirectory()

Debug Folder

;OpenFileRequester("Please choose file to load", Folder, "", 0)

 If ExamineDirectory(0, Folder, "")
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_Directory
        
        ;Filters out . .. and directories starting with .
        If Left(DirectoryEntryName(0) ,1) <>"."
        
          Debug ""
          Debug DirectoryEntryName(0) 
          Debug DirectoryEntryAttributes(0)
        
        EndIf

      EndIf

    Wend
    FinishDirectory(0)
  EndIf
I can understand the . and .. but why is 'Library' shown by ExamineDirectory()?

Same goes for other directories beginning with the . character.

Are they something I should hide from a user? trying to select a file?

CD

Re: ExamineDirectory Results

Posted: Thu Nov 05, 2020 2:59 pm
by collectordave
Just a bit more info.

When I use finder and show hidden files and folders it shows up as a hidden folder.

How to use folder attributes so it isn't shown by examinedir?

And adding a bit more the users Trash folder is also there but is not shown by examining dir?

Re: ExamineDirectory Results

Posted: Mon Nov 09, 2020 7:19 pm
by deseven
As a rule in unix world, all files and directories with names starting with dot are hidden.

HOWEVER, macOS also supports hidden flags on filesystem level. I don't think PB knows about it, but you can easily use NSURL to check. It will return hidden flag for both files and folders starting with . along with files and folders hidden on filesystem level (such as ~/Library).

Code: Select all

If ExamineDirectory(0,GetEnvironmentVariable("HOME"),"*.*")
  While NextDirectoryEntry(0)
    EntryName$ = DirectoryEntryName(0)
    If DirectoryEntryName(0) = "." Or DirectoryEntryName(0) = ".."
      Continue
    EndIf
    If DirectoryEntryType(0) = #PB_DirectoryEntry_File
      Type$ = "[File] "
      Size$ = " (Size: " + DirectoryEntrySize(0) + ")"
    Else
      Type$ = "[Directory] "
      Size$ = "" ; A directory doesn't have a size
    EndIf
    
    path$ = GetEnvironmentVariable("HOME") + "/" + DirectoryEntryName(0)
    NSURL = CocoaMessage(0,0,"NSURL fileURLWithPath:$",@path$)
    CocoaMessage(0,NSURL,"getResourceValue:",@isHidden,"forKey:$",@"NSURLIsHiddenKey","error:",0)
    
    If CocoaMessage(0,isHidden,"boolValue")
      Debug Type$ + "[HIDDEN] " + DirectoryEntryName(0) + Size$
    Else
      Debug Type$ + DirectoryEntryName(0) + Size$
    EndIf
  Wend
  FinishDirectory(0)
EndIf

Re: ExamineDirectory Results

Posted: Tue Nov 10, 2020 3:54 pm
by collectordave
That is brilliant


Thank you.

CD