It is currently Thu Jan 21, 2021 6:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ExamineDirectory Results
PostPosted: Thu Nov 05, 2020 2:52 pm 
Offline
Addict
Addict

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

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ExamineDirectory Results
PostPosted: Thu Nov 05, 2020 2:59 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1181
Location: Portugal
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ExamineDirectory Results
PostPosted: Mon Nov 09, 2020 7:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jan 12, 2011 3:48 pm
Posts: 229
Location: Serbia
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:
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

_________________
PB examples collection
pb-osx-globalhotkeys
pb-osx-notifications


Top
 Profile  
Reply with quote  
 Post subject: Re: ExamineDirectory Results
PostPosted: Tue Nov 10, 2020 3:54 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1181
Location: Portugal
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye