我有一个列表,其中包含文件夹路径谁应该正确连接,以便 rsync
<将多个源文件夹备份到单个源文件夹中/ strong>命令。
这是我到目前为止所做的:
set sourcefolderlist to {"/Volumes/sourcefolder1", "/Volumes/sourcefolder2"}
set localfolder to quoted form of POSIX path of ("/Users/dfdfdf/destinationfolder")
set allSourceFolders to ""
repeat with oneSourceFolder in sourcefolderlist
set allSourceFolders to ((quoted form of POSIX path of allSourceFolders) & oneSourceFolder)
end repeat
因此源路径应位于与 POSIX文件路径(如localfolder
)连接的列表中。
结局应该是这样的:
do shell script "rsync -arvuE " & allSourceFolders & " " & localfolder
如何连接sourcefolderlist
中的项目,以便rsync
可以读取正确的POSIX文件夹路径?
答案 0 :(得分:1)
从手册页:
rsync [OPTION]... SRC [SRC]... DEST
我认为你只是用“”字符将它们分开。
如果您仍需要一个列表作为所有来源的来源(派上用场),请像这样循环:
set sourcefolderlist to {"/Volumes/sourcefolder1", "/Volumes/sourcefolder2"}
set localfolder to quoted form of POSIX path of ("/Users/dfdfdf/destinationfolder")
set sources to ""
repeat with i from 1 to number of items in sourcefolderlist
set sources to sources & " " & quoted form of (item i of sourcefolderlist as text)
end repeat
log sources -- > (* '/Volumes/sourcefolder1' '/Volumes/sourcefolder2'*)
do shell script "rsync -arvuE " & sources & " " & localfolder
BTW:使用AppleScript的内置代码片段:创建一个新行,将“sourcefolderlist”(=包含列表的变量)粘贴到新行中并按CTRL-单击它。选择“重复例程”并从那里“处理每个项目”。
答案 1 :(得分:1)
我编写了一个Applescript脚本库(Join list items v2)来帮助加入Applescript列表项,您还可以在项目中添加引号,因为它们放在最终字符串中。
在这种情况下使用的例子是:
#Needed Use Clauses
use script "you Library name here"
--use scripting additions
set sourcefolderlist to {"/Volumes/sourcefolder1", "/Volumes/sourcefolder2"}
set sources to join list items sourcefolderlist using text space with items in single quotes
-- Result--> "'/Volumes/sourcefolder1' '/Volumes/sourcefolder2'"
版本1的帖子中也是一个小explanation about the library (v1)。它还有关于Applescript脚本库的Apples会话的链接