##################################### # Disk Cataloger - Prompts user for # drive letter, disk name, and output file # scans the disk and produces a text file of all # the files/folders on that disk # # (c) University of Wisconsin - Graphics Group 2004 # Author - Michael Wallick ####################################### import os import os.path import time #Safely changes directory, return 1 if successful 0 otherwise def safe_chdir(pth): try: os.chdir(pth) except os.error: return 0 return 1 def deep_check(pth, fl) : #if need be add to the if statement "pth!= ***" and ... and os.path.isdir(): if os.path.isdir(pth): curr_dir = os.getcwd() if safe_chdir(pth) : dir_list = os.listdir(os.getcwd()) for i in range(len(dir_list)): fl.write("%s\%s\n"%(pth,dir_list[i])) deep_check("%s/%s"%(pth, dir_list[i]), fl) os.chdir(curr_dir) drive_letter = raw_input("Enter the Drive letter: ") disk_name = raw_input("Enter the disk name: ") out_file_name = raw_input("Enter the output file: ") out_file = open(out_file_name, "w") out_file.write("Directory for %s\n"%(disk_name)) out_file.write("Created on %s\n\n"%(time.asctime(time.localtime()))) curr_dir = os.getcwd() os.chdir('%s:/'%(drive_letter)) dir_list = os.listdir(os.getcwd()) for i in range(len(dir_list)): out_file.write("%s\n"%(dir_list[i])) # This is to prevent from look at WINNT folder - there is no need to catalog that anyway # To hack further, add "and dir_list[i]!= ..." if dir_list[i] != "WINNT" : deep_check("%s:/%s"%(drive_letter, dir_list[i]), out_file) out_file.close() os.chdir(curr_dir)