本文介绍了Applescript 将文件复制到新文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个 AppleSript,它将指定的文件从一个文件夹复制到一个新创建的文件夹.
I need to create an AppleSript that will copy specified files from one folder to a newly created folder.
需要在 AppleScript 编辑器中指定这些文件,例如:
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
推荐答案
一般:
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
您可以添加代表 POSIX 文件和路径的变量名称.
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 将文件复制到新文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!