1
我是相當新的蟒蛇,我試圖寫一個腳本來從一個目的地複製.jpgs到另一個。這部分工作,但我試圖排除某些包含某些以「大」,「iphone」和「wbig」結尾的字符串的縮略圖。當我運行它時,我會得到一個「切片索引必須是整數或無或有一個索引方法」。我的另一個問題是,endwidth只需要三個參數......是否有另一種方法可以用來排除更多?查找特定的字符串,複製和重命名
import os, shutil, re
def copy_files_over(src, dest):
src_files = os.listdir(src)
for file_name in src_files:
full_file_name = os.path.join(src, file_name)
full_destination=os.path.join(dest,file_name)
if (os.path.isfile(full_file_name) and )and not file_name.endswith('big', 'iphone' 'wbig')):
while os.path.exists(full_destination):
full_destination += ".duplicate"
shutil.copy(full_file_name, full_destination)
dest = 'C:/image_out'
src= 'C:/image_in'
copy_files_over(src, dest) # copy files
print "test complete";
接下來,我想一旦它移到重命名JPG ...即「My_Picture」將被重新命名爲「My_Picture_Renamed」。我還沒有開始編寫代碼,但任何手指朝着正確的方向都會有所幫助。
謝謝!
謝謝安迪......由於某種原因,包含這些字符串的圖像仍在打印。他們都包括文件名中的字符串「縮略圖」...是否有一種方法可以排除包含字符串「縮略圖」的所有文件?該文件不會以「縮略圖」結尾,所以我不認爲端寬類型會起作用 – Matt