重复文件夹&内容,重命名文件夹,预挂文件夹名称到内容

时间:2014-06-30 20:24:51

标签: applescript

我希望有人能帮忙建一个小苹果。 到目前为止,我还没有找到一个完全符合我需要的解决方案。

我有一个包含多个文件的单个文件夹。 我想做的是复制该文件夹(及其内容)并提示输入该文件夹的新名称。我还希望将该文件夹的新名称预先挂起到其中的所有文件中。将文件夹(和内容)保存到设置位置。 (/用户/大卫/自定义)

EG。原始结构;     文件夹名称:" MainTemplate"     文件夹内容:" about.txt"," photo.jpg"," info.doc"等

发表复制;     文件夹名称:" John The Dog"     文件夹内容:" John The Dog-about.txt"," John The Dog-photo.jpg"," John The Dog-info.doc"等

谢谢你的时间。

NEW

好的,我已经在这工作了5个多小时。重新命名文件是我无法弄清楚的。 有人可以帮我这部分吗?也许,脚本可能会改进? 谢谢!

on run {input, parameters}

tell application "Finder"

    set theFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy"
    set targetFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy-finished"


    display dialog "Which structure do you wish to duplicate?" buttons {"Structure-MAIN", "Structure-OTHER"}
    set chosenStructure to button returned of result


    if contents of chosenStructure is equal to "Structure-MAIN" then
        set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-MAIN"
    else
        set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-OTHER"
    end if


    display dialog "Specify a new folder name:" default answer "John The Dog"
    set newName to (text returned of result)
    set createNewStructure to make new folder at targetFolder with properties {name:newName}


    duplicate every file of entire contents of folder chosenStructure to createNewStructure





    set the_folder to name of folder chosenStructure
    repeat with this_file in (get files of entire contents of folder chosenStructure)

        set the_start to offset of "_" in ((name of this_file) as string)
        set the_stop to count (name of this_file as string)
        set name of this_file to (the_folder & (items the_start thru the_stop of (name of this_file as string)))
    end repeat

end tell


return input
end run

1 个答案:

答案 0 :(得分:0)

你想最小化告诉块。它们越大,你被禁止使用该程序的时间越长。我把它清理了一下,根据你写的内容,下面应该做的。

on run {input, parameters}

set chosenStructure to button returned of (display dialog "Which structure do you wish to duplicate?" buttons {"Structure-MAIN", "Structure-OTHER"})

if chosenStructure is equal to "Structure-MAIN" then
    set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-MAIN"
else
    set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-OTHER"
end if

set newName to text returned of (display dialog "Specify a new folder name:" default answer "John The Dog")

tell application "Finder"
    set theFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy"
    set targetFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy-finished"
    set createNewStructure to make new folder at targetFolder with properties {name:newName}

    duplicate every file of entire contents of folder chosenStructure to createNewStructure

    set the_folder to name of folder chosenStructure
    set folder_Contents to (get files of entire contents of folder chosenStructure)
end tell

repeat with this_file in folder_Contents

    tell application "Finder"
        set the_FileName to name of this_file
        set name of this_file to (the_folder & "-" & the_FileName)
    end tell
end repeat

结束