python 实现endnote下载的pdf文件的整理

endnote下载的文件放在一个pdf文件夹中的一堆乱序数字的文件夹中如图

现在老板要求要把下载下来的文件发给他,, 但一个个拷出来感觉有些蛋疼,于是就想到了python,通过查阅资料,完美实现了这个整理的功能,果然是python大法好2333333333333

最终效果:

本人python菜鸟,写的不好的地方,请见谅

os.pathimport shutil:curpath = ”extension = ”target_dir = :self.curpath = os.getcwd()self.extension = ‘.pdf’self.target_dir = :extension = self.extensionpath = self.curpathif not os.path.isdir(path):# 判断是否为路径print(‘error! it is not a dir’)returnself.makedir()for root, dirs, list in os.walk(path):for file in list:if file.endswith(extension):print(‘moving\t’ + file + ‘\ting……………’)try:self.movefiles(os.path.join(root, file))except:continueprint(‘——————-done—————–‘):target_dir = self.target_dirif not os.path.exists(target_dir):os.mkdir(target_dir):target_dir = self.target_dirshutil.copy(file, target_dir)#instance = classify 缺少() 没有初始化selfinstance = classify()instance.classify_file()

参考资料 1.Python笔记——类定义

2.Python文件操作及文件夹遍历

3.Python的startswith与endswith函数

4.Python shutil模块

5python判断文件和文件夹是否存在

6try..except

美好的生命应该充满期待、惊喜和感激

python 实现endnote下载的pdf文件的整理

相关文章:

你感兴趣的文章:

标签云: