这段代码为python,主要功能包括文件自动分类和清理重复文件,可供大家复制使用。
import os
import glob
import filecmp
import shutil
dir_path = r’C:\xxxx’
file_lst = []
for i in glob.glob(dir_path + ‘/**/*’, recursive=True):
if os.path.isfile(i):
file_lst.append(i)
for x in file_lst:
for y in file_lst:
if x != y and os.path.exists(x) and os.path.exists(y):
if filecmp.cmp(x, y):
os.remove(y)
path = ‘./’
files = os.listdir(path)
for f in files:
folder_name = ‘./’ + f.split(’.’)[-1]
if not os.path.exists(folder_name):
os.makedirs(folder_name)
shutil.move(f,folder_name)
else:
shutil.move(f,folder_name)