使用AppleScript比较两个目录中没有扩展名的文件名

时间:2016-11-04 16:42:09

标签: applescript

在前言中,我做了一个Photoshop批处理操作,将具有数千个不同格式图像的文件夹转换为.pngs。不幸的是,其中一些被跳过了,而另一些则换成了错误的宽高比。

我希望使用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)并让所有文件无法转换或使用不正确的宽高比进行转换列入某种清单。

感谢您的帮助! :)

1 个答案:

答案 0 :(得分:0)

自己解决了!不应该返回source_names / png_names。