views:

767

answers:

2

What is the best way to do cross-platform handling of hidden files? (preferably in Python, but other solutions still appreciated)

Simply checking for a leading '.' works for *nix/Mac, and file attributes work on Windows. However, this seems a little simplistic, and also doesn't account for alternative methods of hiding things (.hidden files, etc.). Is there a standard way to deal with this?

+1  A: 

"Is there a standard way to deal with this?" Yes. Use a standard (i.e., POSIX-compliant) OS.

Since Windows is non-standard -- well -- there's no applicable standard. Wouldn't it be great if there was? I feel your pain.

Anything you try to do that's cross-platform like that will have Win32 oddities.

Your solution is -- for the present state of affairs -- excellent. At some point in the future, Microsoft may elect to write a POSIX-compliant OS. Until then, you're coping well with the situation.

S.Lott
@S.Lott: I normally like your comments, but this is not helpful. There are a number of other modules in the standard library that cope with the non-standard ways of Windows. I'm sure the OP was just looking for something like that.
technomalogical
@technomalogical: True, there are modules that minimize the differences. The point is that non-standard means non-standard. It's a bummer. There's no fairy-dust solution that makes non-standard operating systems appear standard. The OP had a good solution.
S.Lott
+1  A: 

We actually address this in a project we write. What we do is have a number of different "hidden file checkers" that are registered with a main checker. We pass each file through these to see if it should be hidden or not.

These checkers are not only for different OS's etc, but we plug into version control "ignored" files, and optional user overrides by glob or regular expression.

It mostly amounts to what you have done, but in a pluggable, flexible and extensible way.

Ali A
Is this project open source? Can you post source to this code? You give a rough idea of how it works, but an example or pseduo code would be helpful.
technomalogical
Yes, it is open source. http://pida.co.uk/, source code listed here http://pida.co.uk/trac/browser/pida/services/filemanager/. Bear in mind that the architecture for plugging things into this is higher up in the core application, and any other part of code can "register" to use it.
Ali A