import shutil
import os
sourcepath = "/Users/zhouxl/Documents/python小甲魚視頻/小甲魚解壓后"
new_path1 ='/Users/zhouxl/Documents/python小甲魚視頻/小甲魚視頻mp4/'
new_path2 ='/Users/zhouxl/Documents/python小甲魚視頻/小甲魚課件ppt'
new_path3 ='/Users/zhouxl/Documents/python小甲魚視頻/小甲魚py'
for root, folders, files in os.walk(sourcepath):
# os.walk(path), 遍歷path父文件夾,包括其下的所有層級(jí)的子目錄,及所有文件,
# 返回所有層級(jí)路徑(不帶文件名或子目錄名),返回所有子目錄名,返回所有文件名
print(root)
# print(folders)
# print(files)
for file in files:
filename = os.path.join(root, file)
if filename.endswith('.mp4'):
shutil.copy(file, new_path1)
if filename.endswith('.ppt'):
shutil.copy(file, new_path2)
if filename.endswith('.py'):
shutil.copy(file, new_path3)
聯(lián)系客服