Created
March 18, 2012 19:19
-
-
Save douglasmiranda/2079984 to your computer and use it in GitHub Desktop.
Detecting and removing all files that have invalid file names (not ascii names), that cannot be renamed or removed using ssh, in certain posix servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Detecting and removing all files that have invalid file names (not ascii names), | |
that cannot be renamed or removed using ssh, in certain posix servers. | |
""" | |
import glob | |
import os | |
def isascii(s): | |
return all(ord(c) < 128 for c in s) | |
def files_to_rename(_from): | |
return [f for f in glob.glob(_from) if os.path.isfile(f) and not isascii(f)] | |
""" | |
Could be a regex or dir name. | |
More about glob in: http://docs.python.org/library/glob.html | |
""" | |
_from = '*' | |
files = files_to_rename(_from) | |
for f in files: | |
print 'Removing the file: "%s"' % f | |
os.unlink(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment