Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Created March 18, 2012 19:19
Show Gist options
  • Save douglasmiranda/2079984 to your computer and use it in GitHub Desktop.
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.
"""
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