Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gets a list of files that don't belong to my user.
'''
WHICH FILES ARE MINE?
Jeff Thompson | 2015 | www.jeffreythompson.org
'''
import os, pickle, pprint
folder = '/'
my_uid = 501
not_mine = {}
files_walked = 0
files_found = 0
# WHO ARE WE? WHAT ARE WE DOING?
os.system('cls' if os.name=='nt' else 'clear')
print "FILES THAT AREN'T MINE"
print 'Reading from:', folder
print 'Ignoring UID:', my_uid
# LOOK AT EVERYTHING
print '\nWalking all files\n(may take a while!)...'
for root, dirs, files in os.walk(folder):
for f in files:
files_walked += 1
if files_walked % 100000 == 0:
print '-', files_walked, 'files'
try:
full_path = os.path.join(root, f)
stats = os.stat(full_path)
except:
continue
uid = stats[4]
if uid != my_uid:
files_found += 1
if uid in not_mine.keys():
not_mine[uid].append(full_path)
else:
not_mine[uid] = [ full_path ]
print 'Finished!'
# RESULTS
print '\nFiles walked:', files_walked
print 'Files found: ', files_found
percent_mine = (float(files_found)/float(files_walked)) * 100
print 'Percent mine:', "%.2f" % percent_mine, '%'
# WRITE TO FILE
print '\nWriting data to file...'
with open('NotMine.pkl', 'wb') as f:
pickle.dump(not_mine, f)
print '\nALL DONE!\n\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.