def findDups(path): flag = os.path.isabs(path) if flag == False: path = os.path.abspath(path) exists = os.path.exists(path) if exists: dupsfilesDic = {} startTime = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') totalFiles = 0 dupFiles = 0 for dirName, subDir, files in os.walk(path): for fname in files: totalFiles = len(files) fname = os.path.join(dirName, fname) file_hash = Checksum.hashfile(fname) if file_hash in dupsfilesDic: dupsfilesDic[file_hash].append(fname) dupFiles += 1 else: dupsfilesDic[file_hash] = [fname] return dupsfilesDic, startTime, totalFiles, dupFiles else: print("Invalid path")
def DuplicateRemoval(path, to): data = {} for folder, subfolder, files in os.walk(path): for name in files: name = os.path.join(folder, name) checksum = Checksum.hashfile(name) if checksum in data: data[checksum].append(name) else: data[checksum] = [name] filepath = os.path.join(path, "DuplicateFileRemoval.txt") seperator = "-" * 80 f = open(filepath, 'w') f.write(seperator + "\n") f.write("Deleted Duplicate Files\n") f.write(seperator + "\n") f.write("\n") newdata = [] newdata = list(filter(lambda x: len(x) > 1, data.values())) count = 0 for outer in newdata: icnt = 0 for inner in outer: icnt = icnt + 1 if icnt > 1: count = count + 1 os.remove(inner) f.write(inner + "\n") f.write("\nTotal files deleted: %d" % count) f.write("\n") f.close() connected = is_connected() if connected: MailSender("DuplicateFileRemoval.txt", to) else: print("There is no Internet Connection")
def displayDirAllFileChecksum(path): flag = os.path.isabs(path) if flag == False: path = os.path.abspath(path) exists = os.path.exists(path) if exists: with open("OutputDirAllFileChecksum.log", 'w') as fobj: for dirName, subDir, files in os.walk(path): for fname in files: fobj.write("\n" + "-" * 10) fobj.write("\nFilename: " + str(fname)) fname = os.path.join(dirName, fname) fobj.write("\nChecksum: " + str(Checksum.hashfile(fname))) print("Output is stored in OutputDirAllFileChecksum.log file") else: print("Invalid path")
def findDups(path): flag=os.path.isabs(path); if flag == False: path=os.path.abspath(path); exists=os.path.exists(path); if exists: dupsfiles={}; for dirName, subDir, files in os.walk(path): for fname in files: fname=os.path.join(dirName,fname); file_hash=Checksum.hashfile(fname); if file_hash in dupsfiles: dupsfiles[file_hash].append(fname); else: dupsfiles[file_hash]=[fname]; return dupsfiles; else: print("Invalid path");