@bergus
2015-12-02T06:38:29.000000Z
字数 767
阅读 2283
python python模块 shutil
# encoding=utf-8# /home/bergus/tongbu/360共享/编程语言# /home/bergus/桌面# /home/bergus/test/hhimport osimport shutil# 把文件src_file移动到目录dest_filedef move(src_file, dest_file):for src in src_file:for dest in dest_file:try:shutil.move(src, dest)except Exception, e:print e# 得到关键字的路径def get_keyworld_paths(key_word, path):dest_dirs = []if os.path.exists(path):for f in os.listdir(path):# print fif key_word in f.lower():dest_dirs.append(os.path.join(path, f).replace('\\', '/'))return dest_dirsdef my_move():src_dir = '/home/bergus/桌面'dest_dir = '/home/bergus/tongbu/360共享/编程语言'key_word = ['python', 'flask', 'sqlalchemy']for key in key_word:try:a1 = get_keyworld_paths(key, src_dir)a2 = get_keyworld_paths(key, dest_dir)move(a1, a2)print "移动完成"except Exception, e:print eif __name__ == '__main__':my_move()
