If you need a more comprehensive guide about it, take a look at the How to Traverse a Directory Tree in Python article. The findDup function is using os.walk to traverse the given directory. Now we need a function to scan a directory for duplicated files:įor dirName, subdirs, fileList in os.walk(parentFolder): The function receives the path to the file and returns the HEX digest of that file: Then we need a function to calculate the MD5 hash of a given file. To start, import the os, sys and hashlib libraries: All of the files that we find are going to be stored in a dictionary, with the hash as the key, and the path to the file as the value. This program is going to compute a hash for every file, allowing us to find duplicated files even though their names are different. The program is going to receive a folder or a list of folders to scan, then is going to traverse the directories given and find the duplicated files in the folders. In this tutorial we are going to code a Python script to do this. Sometimes we need to find the duplicate files in our file system, or inside a specific folder. Last Updated: Wednesday 29 th December 2021
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |