2017-02-20 76 views
0

还有一个小白/新手在这里的AppleScript到一个文件夹中重命名文件

所以我想一个文件夹中重命名文件

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 got an error: Can’t set file \"DVD_template.dspproj\" to \"newfoldername.dspproj\"." number -10006 from file "DVD_template.dspproj""

我已经尝试了各种方法,有和没有扩展名“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 

回答

0

您试图重命名这显然不存在桌面文件“DVD_template.dspproj”。桌面文件夹是Finder的根文件夹

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. 
+0

我可以(一些奇怪的原因)得到它重命名文件,但向后所以它会而不是重命名模板文件名采取新的文件夹名称“newfoldername”并重命名文件“DVD_Template.dspproj” –

+0

该名称应该是早先声明的变量名称是“newnamefolder”,我已经添加了上面的所有代码 –

+0

确切的预期**文件名**(最后一个路径组件)在上面的例子中? – vadian

相关问题