Discussion:
Ignoring invisible files
Kim Kohen
2007-01-23 01:22:48 UTC
Permalink
hi folks,

I'm wondering if there's a way to ignore invisible files when
navigating a folder?

I'm using f.count to count items in a folder but when looping through
it's also reading things like the .ds_store files - which I want to
ignore. Is there some simple way of ignoring them all or should I
write a conditional to pass over particular files when looping?

cheers and thanks

kim
RBNUBE
2007-01-23 01:29:37 UTC
Permalink
It think FolderItem.Visible = True should ignore the hidden files.
Kim Kohen
2007-01-23 02:55:09 UTC
Permalink
hi RBNUBE,
Post by RBNUBE
It think FolderItem.Visible = True should ignore the hidden files.
••••
perfect, thanks


cheers

kim
Arnaud Nicolet
2007-01-23 12:22:23 UTC
Permalink
That's true, but not complete.
Under Mac OS X, files whose name starts with "." are invisibles,
beside the fact that the .visible property is still true. You should
check for the name, if it starts with ".", it's also invisible.
Also, still under Mac OS X, there can be a file named ".hidden" in
the current folder. If it exists, it contains name of files that are
also invisibles, even if the name does not start with "." and
the .visible property is true. You should read the file as text to
discover these invisibles files (I'm not sure what is the purpose of
this ".hidden" file nor who can modify it).
Post by RBNUBE
It think FolderItem.Visible = True should ignore the hidden files.
Harrie Westphal
2007-01-24 02:50:46 UTC
Permalink
Post by Arnaud Nicolet
That's true, but not complete.
Under Mac OS X, files whose name starts with "." are invisibles,
beside the fact that the .visible property is still true. You
should check for the name, if it starts with ".", it's also invisible.
Also, still under Mac OS X, there can be a file named ".hidden" in
the current folder. If it exists, it contains name of files that
are also invisibles, even if the name does not start with "." and
the .visible property is true. You should read the file as text to
discover these invisibles files (I'm not sure what is the purpose
of this ".hidden" file nor who can modify it).
Here is a global method, because of the "extends" option, which is
used to verify that a file is visible or not and it is incorporating
the items that Arnaud mentions above. It returns true if file IS
visible and false if the file IS NOT visible. Note that at some point
in time it seems that OS X quit using the ".hidden" files to name
files that are to be invisible within the parent folder. At least I
have never been able to find one in more recent versions of OS X.
However, I leave the code in this routine in case it is used in an
older OS X version.

Function isVisible(Extends f As FolderItem) As Boolean
// This method, gotten from one of the RB mailing lists, returns
// True if the folderitem passed to it is a visible file and False
// if it is not. It checks for first character being a decimal
// point, if the filename exists in the .hidden file, and if the
// visible bit of the folderitem is true or not.
#if TargetCarbon
Dim sysx As Integer
Dim fp As FolderItem
Dim ts As TextInputStream
Dim hideFiles As String
#endif

if f.Visible Then
#if TargetCarbon
if System.Gestalt("sysv",sysx) and sysx > &h1000 then
if Left(f.name,1) = "." then return false
fp = f.parent
if fp = nil then Return True
fp = fp.child(".hidden")
if fp <> nil and fp.exists and fp.IsReadable then
ts = fp.OpenAsTextFile
hideFiles = chr(10) + ts.ReadAll + chr(10)
if InStr(hideFiles,chr(10) + f.Name + chr(10)) > 0 then
Return False
end if
end if
#endif
return true
end if

#if debugBuild then
#else
exception err
errorAnnouncer err,"isVisible method of the globalStuff module"
#endif

End Function


=== A Mac addict in Tennessee ===
Lars Jensen
2007-01-24 20:41:25 UTC
Permalink
Post by Harrie Westphal
Function isVisible(Extends f As FolderItem) As Boolean
Implementation note: Even if I am running on Windows or Mac Classic, I
generally find it useful to check for Mac OS X style invisibility as
described in this thread. In the mixed-platform networks that are my
usual haunts, a filename that starts with a period is very likely to
be a remnant of Mac OS X access to that network folder, and not
something I want to show in the user interface of whatever tool I am
writing.

So instead of the IsVisible function above, my function looks like this:

Function IsHidden(extends f as folderItem, CrossPlatform as boolean
= true) as boolean

Inside this function, I don't use platform-specific compilation;
instead I check the CrossPlatform argument to decide which tests to
perform. This allows me to offer it as a runtime option for the user,
appropriate.

(This function is part of the FolderItemHelpers module in UTool:

http://ljensen.com/utool

I chose IsHidden instead of IsVisible to make the function name more
distinct from RB's Visible property. That might have been a mistake,
because people who search for "Visible" will tend to find "IsVisible",
which is good.)

lj
Arnaud Nicolet
2007-01-24 20:51:26 UTC
Permalink
Post by Lars Jensen
Post by Harrie Westphal
Function isVisible(Extends f As FolderItem) As Boolean
Implementation note: Even if I am running on Windows or Mac Classic, I
generally find it useful to check for Mac OS X style invisibility as
described in this thread. In the mixed-platform networks that are my
usual haunts, a filename that starts with a period is very likely to
be a remnant of Mac OS X access to that network folder, and not
something I want to show in the user interface of whatever tool I am
writing.
Function IsHidden(extends f as folderItem, CrossPlatform as boolean
= true) as boolean
Inside this function, I don't use platform-specific compilation;
instead I check the CrossPlatform argument to decide which tests to
perform. This allows me to offer it as a runtime option for the user,
appropriate.
That's a great idea.

Continue reading on narkive:
Loading...