我試圖給出自己的擴展目錄中的文件進行排序,但所提供的命令,我給第一個。比方說,我想擴展爲了我如何排序給定一個特定的順序,我提供
ext_list = [ .bb, .cc , .dd , aa ]
,我能想到的是要經過的每一個文件 ,每遇到一個具體的延長時間將它們放置在列表中的唯一方法。
for subdir, dirs, files in os.walk(directory):
if file.endswith('.bb') --> append file
then go to the end of the directory
then loop again
if file.endswith('.cc') -->append file
and so on...
return sorted_extension_list
,最後
for file in sorted_extension_list :
print file
爲什麼你不能在一個鏡頭中得到整個列表,然後檢查每個擴展名?這樣做你只會得到一個完整的列表,你可以在那裏工作。希望這有助於完成您的想法。 –