我不想把所有档案改名为目录。 视窗探测器名称排列后,按正确顺序排列:
Cue 001 - 002.mp3
...
Cue 001 - 010.mp3
Cue 001 - 011.mp3
...
Cue 001 - 020.mp3
Cue 001 - 021.mp3
...
Cue 001 - 0111.mp3
Cue 001 - 0112.mp3
到目前为止,我已经能够使用<代码>os.chdir,将工作名录改为有目标文档的名录,并通过使用<代码>印(os.getcwd()加以确认。
import os
# Lets change working directory to the Python Rename Test folder
os.chdir(r F:My backupDocuments and SettingsuserMy DocumentsMy MusicThe CommitmentsThe Commitments - Mustang Sally_RecursiveBackupPython Rename Test )
# confirm working directory by printing it out
print (os.getcwd())
# loop over the files in the working directory and printing them out
for file in os.listdir(os.getcwd()):
print (file)
This is what I get:
Cue 001 - 002.mp3
...
Cue 001 - 010.mp3
Cue 001 - 0100.mp3
Cue 001 - 0101.mp3
...
我怎样才能获得<代码>os.listdir,以便按适当顺序打印文件?