简单的移动文件的脚本
家里的home server,使用mldonkey下载资源(见这里),有视频和电子书等,需要编写个脚本,将不同后缀的文件移动到指定的目录下。 这里使用python,写了个简单的脚本: #!/usr/bin/python # -*- coding: utf-8 -*- import os scan_path=”/Users/marshal” book_path=”/Users/marshal/books” def file_action(file): if(file.endswith(“.pdf”) or file.endswith(“.epub”)): os.rename(scan_path+’/’+file, book_path+’/’+file) print ‘移动文件:’,file print “开始文件整理,目录:”,scan_path,” …” if(os.path.exists(book_path) is False): os.mkdir(book_path) #print os.getcwd() files=os.listdir(scan_path) for file in os.listdir(scan_path): file_action(file) print “整理完毕。” 发送文章为PDF