Original Folder A, B, new Folder C, in the case of pictures as an example
A:00001.jpg 00002.jpg 00003.jpg 00147.jpg
B:00001.jpg 000000002.jpg 00147.json
The first case: Find files with the same contents under two folders, save and output to folder C
Idea: Determine whether the content is consistent, so you need to read the entire file to determine whether the two are the same
Because the content of the file is complex and its MD5 is unique, the MD5 value should be the same if both contents are consistent. Since the picture is binary storage, it uses ' RB ' when reading. Here is the MD5 value processing for the file contents. The type of each file name is str format. Generate a dictionary of files under a file to determine if the file under B is in a generated dictionary, and if it exists, it will exist under the new folder C.
The code is:
The second case: if the file name in the A and B folders is consistent, do not care about the consistency of the content, if the file name is consistent, save in the new folder. The difference between this and the situation one is that the file name is MD5 processed.
The filename needs to be encoded and will be error-coded.
The third case: the file name in B and the files in the a folder, such as a file under the Jian folder 000147.json, need to be based on the method of string extraction to determine whether there is content consistent
According to the actual situation to make corresponding adjustments.
Reference article link: https://zhidao.baidu.com/question/984682642027858179.html
Use Python to find the same files in two folders and save them in a new folder (in three cases)