2016-11-04 64 views
0

爲了序言,我做了一個Photoshop批處理操作,它將具有數千個不同格式圖像的文件夾轉換爲.png。不幸的是,其中一些被跳過,另一些則被錯誤的長寬比轉換。使用AppleScript比較兩個目錄中沒有擴展名的文件名

我希望能夠比較使用Applescript的文件夾。目前我只想找到哪些文件通過,哪些沒有。我希望用戶能夠選擇源文件和已轉換的文件夾,然後需要去除文件擴展名以比較每個文件夾中的文件名。以下是我迄今爲止所寫的內容;它似乎在end tell聲明後停止。我究竟做錯了什麼?

--Set folder paths 
display dialog "Choose the source folder containing images with correct aspect ratios" 
set source_folder to (choose folder) 

display dialog "Choose the folder containing PNGs to compare to" 
set png_folder to (choose folder) 

--Create lists of folder contents for each folder 
tell application "System Events" 
    set source_filenames to name of every file of source_folder 
    set source_extensions to name extension of every file of source_folder 

    set png_filenames to name of every file of png_folder 
    set png_extensions to name extension of every file of png_folder 
end tell 

--Collect names (filename minus dot and extension) 
set source_names to {} 
repeat with n from 1 to count of source_filenames 
    set source_filename to item n of source_filenames 
    set source_extension to item n of source_extensions 

    if source_extension is not "" then 
     set source_filename_length to (count of source_filename) - (count of source_extension) - 1 
     set end of source_names to text 1 thru source_filename_length of source_filename 
    else 
     set end of source_names to source_filename 
    end if 
end repeat 
return source_names 

set png_names to {} 
repeat with n from 1 to count of png_filenames 
    set png_filename to item n of png_filenames 
    set png_extension to item n of png_extensions 

    if png_extension is not "" then 
     set png_filename_length to (count of png_filename) - (count of png_extension) - 1 
set end of png_names to text 1 thru png_filename_length of png_filename 
    else 
     set end of png_names to png_filename 
    end if 
end repeat 
return png_names 

--Compare each item of source folder to png folder 
repeat with n from 1 to the count of source_names 
    set theFile to (item n of source_names) 
    if theFile is in png_names then 
     log "Match found for file " & theFile 
     set foundFile to true 
    else 
     log "No match found for file " & theFile 
     set foundFile to false 
    end if 
end repeat 

後來,我想比較縱橫比(用此線程爲指導http://macscripter.net/viewtopic.php?id=38308),並有所有這些既沒有得到轉化或轉化與不正確的長寬比投入某種文件列表。

感謝您的幫助! :)

回答

0

解決它自己!不應該返回source_names/png_names。

相關問題