ExamineDirectory Results

Mac OSX specific forum
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

ExamineDirectory Results

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ExamineDirectory Results

Post 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?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: ExamineDirectory Results

Post 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
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ExamineDirectory Results

Post by collectordave »

That is brilliant


Thank you.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply