Skip to content

Instantly share code, notes, and snippets.

@Rudis1261
Created November 24, 2013 19:14
Show Gist options
  • Save Rudis1261/7631097 to your computer and use it in GitHub Desktop.
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.
#!/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