def DuplicateFilesRemove(Directoryname): if not os.path.exists(Directoryname): os.mkdir(Directoryname) dups = {} filename = os.path.join(Directoryname, "Log.txt") fobj = open(filename, "w") for Folder, SubFolders, Files in os.walk(Directoryname): print(Folder) for file in Files: path = os.path.join(Folder, file) path1 = MarvellousChecksum.hashfile(path) if path1 in dups: dups[path1].append(path) fobj.write(file) else: dups[path1] = [path] fobj.close() data = [] count = 0 data = list(filter(lambda z: len(z) > 1, dups.values())) for i in data: icnt = 0 for j in i: icnt += 1 if icnt >= 2: count += 1 print("Delete", j) os.remove(j) print("Total file deleted", count)
def DirectoryDusplicate(path, mailId): flag = os.path.isabs(path) if flag == False: path = os.path.abspath(path) exists = os.path.isdir(path) data = {} scannfile_count = 0 if exists: Starting_time = time.time() for foldername, subfolder, filname in os.walk(path): for filen in filname: filen = os.path.join(foldername, filen) checksum = MarvellousChecksum.hashfile(filen) if checksum in data: scannfile_count += 1 data[checksum].append(filen) else: scannfile_count += 1 data[checksum] = [filen] newdata = [] newdata = list(filter(lambda x: len(x) > 1, data.values())) ProcessLog(newdata, scannfile_count, Starting_time, mailId) #MailSender.send(filename,sys.argv[2],scannfile_count,time) #print("total scannfile file=",scannfile_count) else: print("Invalid path ")
def Display(path): flag = os.path.isabs(path) if flag == False: path = os.path.abspath(path) exists = os.path.isdir(path) if exists: for foldername, subfolder, filname in os.walk(path): print("Current folder is :" + foldername) for filen in filname: path = os.path.join(foldername, filen) #print(path) file_hash = MarvellousChecksum.hashfile(path) return file_hash print("----------------------") print("") else: print("Invalid path ")
def DirectoryDusplicate(path): flag = os.path.isabs(path) if flag == False: path = os.path.abspath(path) exists = os.path.isdir(path) data = {} if exists: for foldername, subfolder, filname in os.walk(path): for filen in filname: filen = os.path.join(foldername, filen) checksum = MarvellousChecksum.hashfile(filen) if checksum in data: data[checksum].append(filen) else: data[checksum] = [filen] newdata = [] newdata = list(filter(lambda x: len(x) > 1, data.values())) #print(newdata) count = 0 line = "-" * 40 fobj = open("Log.txt", 'w') fobj.write(line + "\n") fobj.write("Marvellous names of duplicate files\n") fobj.write(line + "\n") for outer in newdata: icnt = 0 for inner in outer: icnt += 1 if icnt >= 2: count += 1 #print("filename",inner) fobj.write(inner + "\n") os.remove(inner) print("Total Duplicate files ", count) fobj.close() else: print("Invalid path ")
def DuplicateFiles(Directoryname): if not os.path.exists(Directoryname): os.mkdir(Directoryname) dups = {} filename = os.path.join(Directoryname, "Log.txt") fobj = open(filename, "w") for Folder, SubFolders, Files in os.walk(Directoryname): print(Folder) for file in Files: path = os.path.join(Folder, file) path1 = MarvellousChecksum.hashfile(path) if path1 in dups: dups[path1].append(path) fobj.write(file) else: dups[path1] = [path] fobj.close()