import os
xlsbpath=r"f:\data"
os.chdir(xlsbpath) #更改當前路徑
filelist = os.listdir(xlsbpath) # 該資料夾下所有的檔案(包括資料夾)
print(filelist) #資料夾中所有檔名
old="last.xlsb" #舊檔名
new="to.xlsb" #新檔名
os.rename(old,new) #重新命名
直接修改檔名
#先複製再改名
#pip install shutil #就是這個庫
#pip install pytest-shutil 上一行出錯嘗試此行
import os
import shutil #複製檔案的庫
xlsbpath=r"f:\data"
os.chdir(xlsbpath)
filelist = os.listdir(xlsbpath) # 該資料夾下所有的檔案(包括資料夾)
print(filelist) #資料夾中所有檔名
old="last.xlsb" #舊檔名
new="to.xlsb" #新檔名
shutil.copy(old,new) #複製後命名
先把原來的檔案複製一下,然後更改新檔案的名稱 更改檔名
import os 輸入資料夾位址 path home zhengsc desktop aug output files os.listdir path 輸出所有檔名,只是為了看一下 for file in files print file 獲取舊名和新名 i 0 for file in files...
Python批量更改檔名
由於後台資料有好多,但是文案提供過來的命名全部沒有按照格式來命名,python這麼強大的語言,肯定是能夠處理這個問題的,於是我就寫了乙個小指令碼批量改檔名。我的思路是這樣的,在當前檔案下建立乙個新的目錄newfile,然後把所有的檔案拷貝過去重新命名一下就行了 文案提供過來的全部都是1.jpg,2....
python 批量更改檔名
為了演示,我建立了乙個資料夾,在檔案路徑 f 新建資料夾 list 下面建立day1 day4共計4個子資料夾,裡面分別放了6個txt文字檔案,如下圖 現在我要做的是將檔案中 學習 字元去除,如下,在命令提示符中的 f 新建資料夾 目錄下執行 python 檔名稱.py addr r f 新建資料夾...