0
我有一個名爲source的列表,用於存儲文件名。現在基於每個文件的擴展名,我希望它複製到不同的文件夾。我知道這是一個非常簡單的任務,但不知何故,我沒有得到它。她是我的代碼:使用Python將文件複製到基於擴展名的不同目錄中
import shutil , os
source = ['test_sound.wav','ts.raw']
src= '/home/GM/codec_implement/Audio_files'
destination1= '/home/GM/codec_implement/raw_files'
destination2= '/home/GM/codec_implement/raw_files/wave_files'
for files in source:
fileName, fileExtension = os.path.splitext(files)
if (fileExtension=='.raw'):
full_filename = os.path.join(source, files)
shutil.copy(full_filename,destination1)
elif (fileExtension=='.wav'):
full_filename = os.path.join(source, files)
shutil.copy(full_filename,destination2)
else:
print "This is not a valid file format "
錯誤:我得到這樣意外的縮進錯誤都是我不的時候明白的地方,我會犯錯,我使用Python 2.7
'''文件名,fileExtension = os.path.splitext(文件)'''應縮進。 – wwii 2014-09-18 18:05:15