1

I am moving some files with a python script. The script should work on both osx and windows.

I am using the the glob module to select the files. Filter out directories with isfile method from os.path. The glob module automatically ignores unix . files but it seems that it does grab some windows hidden files. I have added code to remove one "desktop.ini" that seems to have appeared in windows.

Are there any other Windows files that might appear or is there a way to ensure that I do not select hidden files in Windows?

files = glob.glob('*')
files = filter(os.path.isfile, files)  # filter out dirs
if "desktop.ini" in files : files.remove('desktop.ini')
# then using "shutil.move" to actually move the files
Joop
  • 7,840
  • 9
  • 43
  • 58
  • 1
    possible duplicate of [Cross platform hidden file detection](http://stackoverflow.com/questions/284115/cross-platform-hidden-file-detection) – Piotr Dobrogost Jul 10 '13 at 11:04
  • Does this answer help? (Windows only API) http://stackoverflow.com/a/14063074/233608 – will-hart Jul 10 '13 at 12:03
  • thanks got some pointers from links. Feels a bit convoluted though. Hoped that the glob module would have some platform independent magic in there. – Joop Jul 10 '13 at 14:11
  • Jason R. Coombs's answer at http://stackoverflow.com/questions/284115/cross-platform-hidden-file-detection can used for cross platform added some code to do that. Scoured glob documentation to no avail, but I suspect it is a unix tool so it is not very friendly with windows use. Should I delete question? @PiotrDobrogost – Joop Jul 12 '13 at 14:33

1 Answers1

1

You might want to try Formic.

from formic import FileSet
fileset = FileSet(directory="/some/where/interesting",
              include="*.py",
              exclude=["desktop.ini", ".*", "addition", "globs", "here"]
              )
for filename in fileset:
    # use shutil to move them

This is a Python library using Globs, but i) already understands most hidden files (list of builtins here), and ii) allows you to specify any files to exclude from the results (documentation)

Disclosure: I am the maintainer.

Andrew Alcock
  • 19,401
  • 4
  • 42
  • 60