This program is used to cleanup any folder that you specify but is used here primarily to cleanup a profile in Windows. The purpose of this program to to clean out a profile that may be located in a lab setting (such as at a university). The primary reason that this program was written was that it is impossible to log off of a computer if one's profile is too large.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import os, sys def main(path=''): if len(sys.argv) == 1 and len(path) != 0: try: delete(path) except: print 'ERROR: Internal Path' else: try: delete(' '.join(sys.argv[1:])) except: print os.path.basename(sys.argv), '<directory>' def delete(path): for name in os.listdir(path): path_name = os.path.join(path, name) try: if os.path.isdir(path_name): delete(path_name) os.rmdir(path_name) elif os.path.isfile(path_name): os.remove(path_name) except: print 'ERROR:', path_name if __name__ == '__main__': main(r'C:\Documents and Settings\SCHAP472')
Note: delete() is not supposed to remove the path that it was given.
Windows. Most of the code that I write is for Windows. :)