
主要是理解好上面的1~3點的內容,理解三個返回值所代表的意思。如果不清楚的話,可以在代碼的for循環的第一句注釋輸出看看各個代表的是什么
再者就是對 shutil.copy(file_path,newpath) 中兩個參數的理解,一個是源文件的路徑,另一個是目的路徑。
import shutil,os,re new_path='G:\\PX\\PY' for derName, subfolders, filenames in os.walk('G:\\PY\\text'):
#print(derName/subfolders/filenames) for i in range(len(filenames)): if filenames[i].endswith('.mp4'): file_path=derName+'\\'+filenames[i] newpath=new_path+'\\'+filenames[i] shutil.copy(file_path,newpath)
參考:https://blog.csdn.net/xuan314708889/article/details/79619732
《Python編程快速上手—讓繁瑣工作自動化 》
