【问题标题】:Applescript to rename a file in a folderApplescript重命名文件夹中的文件
【发布时间】:2017-02-20 14:51:50
【问题描述】:

这里还是菜鸟/新手

所以我正在尝试重命名文件夹中的文件

set newfoldername to DT & "-" & JobName & " - " & Wedding --Adds Date, Couples name and event type to make directory name

更多代码在这里

set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
   duplicate file sourcedvdtemp to folder destFolder
   set the name of file "DVD_template.dspproj" to newfoldername
end tell

但我只是得到一个错误

"error "Finder 出现错误:无法将文件 \"DVD_template.dspproj\" 设置为 \"newfoldername.dspproj\"。" 来自文件 "DVD_template.dspproj" 的编号 -10006"

我尝试了各种方法,上面设置了带有和不带有扩展名“newfoldername”,并使用用户输入的名称创建了一个文件夹

我只是愚蠢还是我完全错过了什么。

编辑

tell application "Finder" to set frontmost to true
set DT to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set JobName to text returned of (display dialog "Please enter the couples name" default answer "Bride & Groom + Surname") --Asks for couples name
set Wedding to text returned of (display dialog "Please enter the type of day" default answer "Wedding") --Asks for type of day, Wedding, Party, etc
--Creates directory with info from above
set loc to (choose folder "Please choose where you would like to save the files") as text --Loc = Location of where directory will be placed
set newfoldername to DT & "-" & JobName & " - " & Wedding --Adds Date, Couples name and event type to make directory name
set folderStructure to "/{Audio/{Music,RAW\\ Audio\\ Cards},Documents,Exports,FCPX\\ Library,Film\\ Poster,Final\\ Delivery/{DVD,USB,WEB},Images/{Graphics,Stills},RAW\\ Cards/{C100-1,C100-2,7D,100D},XML}"
do shell script "mkdir -p " & quoted form of POSIX path of (loc & newfoldername) & folderStructure

set sourcedvdtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:DVD_template.dspproj" --Gets file DVD_template
set sourceusbtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:USB_template.zip" --Gets file USB_template
set sourcewebtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:WEB_template.zip" --Gets file WEB_template
set sourcefcpxtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:FCPX_template.fcpbundle" --Gets file FCPX_template
set sourcefilmpostemp to (path to movies folder as text) & "## - WeddingTemplate - ##:FILM_POSTER_Template.psd" --Gets file FILM_POSTER_template

set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
    duplicate file sourcedvdtemp to folder destFolder
    set the name of file "DVD_template.dspproj" to newfoldername
end tell

set destFolder to loc & newfoldername & ":FCPX Library:"
tell application "Finder"
    duplicate file sourcefcpxtemp to folder destFolder
    set the name of file "FCPX_template.fcpbundle" to newfoldername
end tell

set destFolder to loc & newfoldername & ":Film Poster:"
tell application "Finder"
    duplicate file sourcefilmpostemp to folder destFolder
    set the name of file "FILM_POSTER_Template.psd" to newfoldername
end tell

【问题讨论】:

    标签: applescript


    【解决方案1】:

    您正在尝试重命名桌面上明显不存在的文件“DVD_template.dspproj”。桌面文件夹是 Finder 的 root 文件夹。

    Finder 的duplicate 命令返回重复的文件,所以很简单

    tell application "Finder"
       set fileExtension to name extension of file sourcedvdtemp
       set duplicatedFile to duplicate file sourcedvdtemp to folder destFolder
       set name of duplicatedFile to newfoldername & "." & fileExtension
    end tell
    

    如果要将文件重命名为newfoldername,则必须复制并添加文件扩展名。

    PS:建议不要计算模板文件夹5次,而是写

    set weddingTemplateFolder to (path to movies folder as text) & "## - WeddingTemplate - ##:"
    set sourcedvdtemp to weddingTemplateFolder & "DVD_template.dspproj" --Gets file DVD_template
    set sourceusbtemp to weddingTemplateFolder & "USB_template.zip" --Gets file USB_template 
    ... etc.
    

    【讨论】:

    • 我可以(出于某种奇怪的原因)让它重命名文件但向后,因此它将重命名模板文件名,而不是采用新文件夹名称“newfoldername”并重命名文件“DVD_Template.dspproj "
    • 名称应该是前面声明的变量,它是“newnamefolder”,我已经添加了上面的所有代码
    • 上例中所期望的文件名(最后一个路径组件)是什么?
    • 将 newfoldername 设置为 DT & "-" & JobName & " - " & Wedding 这是用户(我)输入的信息,它应该出现在 YYYY/MM/DD - NAME - EVENT.dspproj
    • 这似乎成功了,今晚晚些时候再做一些测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    相关资源
    最近更新 更多