Python code example: compare filenames in two folders and print identical files

Python code example: compare filenames in two folders and print identical files

In this blog, we will explain how to write code using Python to compare filenames in two folders and print out the filenames that exist in the second folder in the first folder. Through this sample code, we can quickly find the same files in the two folders and perform further processing.

# 导入新查找的文件夹,并遍历所有列表  
import os  
  
# 设置文件夹路径  
folder_path = 'F:/BaiduSyncdisk/05since_study/03水下字幕描述/数据集/标注数据集/015 2023年7月8号添加'  
  
# 获取文件夹下所有文件的文件名  
search_target = os.listdir(folder_path)  
  
# 打印文件名列表  
# for file_name in search_target:  
#     print(file_n

Guess you like

Origin blog.csdn.net/lihuanyu520/article/details/131614006