Created
November 24, 2013 19:14
-
-
Save Rudis1261/7631097 to your computer and use it in GitHub Desktop.
Someone else's script which I adapted to remove all the nasty Windows "Thumbs.db" files from my linux media drives.
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
#!/usr/bin/python | |
import os | |
def findNremove(path,pattern,maxdepth=1): | |
cpath=path.count(os.sep) | |
for r,d,f in os.walk(path): | |
if r.count(os.sep) - cpath <maxdepth: | |
for files in f: | |
#print files | |
if files == pattern: | |
try: | |
print "Removing %s" % (os.path.join(r,files)) | |
os.remove(os.path.join(r,files)) | |
except Exception,e: | |
print e | |
else: | |
print "%s removed" % (os.path.join(r,files)) | |
findNremove("/media/usb0","Thumbs.db", 10) | |
findNremove("/media/usb1","Thumbs.db", 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment