Applescript将文件复制到新文件夹 [英] Applescript Copy file to a new folder
问题描述
我需要创建一个AppleSript,它将指定的文件从一个文件夹复制到新创建的文件夹。
这些文件需要在AppleScript编辑器中指定例如:
开始
fileToBeMoved =桌面/测试文件夹1 / test.doc
newfoldername =Test Folder 2
make newfolder并将其命名为'newfoldername'
将'fileToBeMoved'复制到'newfolder'
end
pre> 告诉应用程序Finder
用别名Macintosh HD:Users:user:Desktop:创建新文件夹,其属性为{name:Test Folder 2}
复制文件Macintosh HD:用户:用户:桌面:测试文件夹1:test.doc到文件夹Macintosh HD:用户:用户:桌面:测试文件夹2
end tell
您可以添加表示POSIX文件和路径的变量名。
显然,冒号字符(:)是文件夹和文件名的保留字符。
将desktopFolder设置为Macintosh HD / Users / user / Desktop /
将desktopFdrPosix设置为POSIX路径的引用形式of desktopFolder
将newFolderName设置为Test Folder 2
将destinationFdrPosix设置为desktopFdrPosix& POSIX文件newFolderName
将sourceFilename设置为Test Folder 1 / test.doc
将sourceFnPosix设置为desktopFdrPosix& POSIX文件sourceFilename
告诉应用程序Finder
在别名desktopFdrPosix上创建新文件夹,其属性为{name:newFolderName}
将文件sourceFnPosix复制到文件夹destinationFdrPosix
end tell
如果目标文件夹已存在,您可能还想添加错误检查。
I need to create an AppleSript that will copy specified files from one folder to a newly created folder.
These files need to be specified in the AppleScript editor so something like:
start
fileToBeMoved = "Desktop/Test Folder 1/test.doc"
newfoldername = "Test Folder 2"
make newfolder and name it 'newfoldername'
copy 'fileToBeMoved' to 'newfolder'
end
Generally:
tell application "Finder"
make new folder at alias "Macintosh HD:Users:user:Desktop:" with properties {name:"Test Folder 2"}
copy file "Macintosh HD:Users:user:Desktop:Test Folder 1:test.doc" to folder "Macintosh HD:Users:user:Desktop:Test Folder 2"
end tell
You can add variable names that represent POSIX files and paths.
Obviously the colon character (:) is a reserved character for folder- and filenames.
set desktopFolder to "Macintosh HD/Users/user/Desktop/"
set desktopFdrPosix to quoted form of POSIX path of desktopFolder
set newFolderName to "Test Folder 2"
set destinationFdrPosix to quoted form of desktopFdrPosix & POSIX file newFolderName
set sourceFilename to "Test Folder 1/test.doc"
set sourceFnPosix to quoted form of desktopFdrPosix & POSIX file sourceFilename
tell application "Finder"
make new folder at alias desktopFdrPosix with properties {name:newFolderName}
copy file sourceFnPosix to folder destinationFdrPosix
end tell
You may also want to add error checking if the destination folder already exists.
这篇关于Applescript将文件复制到新文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!