我有一个PDF文件夹,大约650.我有一个excel列表,其中包含我必须将它们合并为一个PDF的PDF列表。
我找到了这个脚本:
tell application "Microsoft Excel"
tell active sheet
set fileList to value of used range
tell used range
set rc to count of rows
end tell
end tell
end tell
set rootFolder to "/Users/aldoopenhouse/Desktop/EN ATTENTE/test cahier de details/Master Detail Book/PDF" as POSIX file
set filesToMove to {}
repeat with thisItem in fileList
try
set end of filesToMove to alias (rootFolder & thisItem)
on error
display dialog "File " & thisItem & " is not in the folder"
end try
end repeat
tell application "Finder"
move filesToMove to folder "/Users/aldoopenhouse/Desktop/EN ATTENTE/test cahier de details/*RESULT" as POSIX file
end tell
此脚本始终会对结果进行撤消:file *********.pdf
不在文件夹
我做错了什么?
答案 0 :(得分:0)
我认为你的文件夹是" PDF"内部文件夹" Master Detail Book"。当你连接rootFolder和ThisItem时,分隔符":"不见了。
你尝试在filestoMove结束时添加的内容是"用户:aldoopenhouse:桌面:EN ATTENTE:测试cahier de details:Master Detail Book:PDFthisitem"
应该在哪里"用户:aldoopenhouse:桌面:EN ATTENTE:测试cahier de details:Master Detail Book:PDF:thisitem" (添加":")
然后说明应该是:
set end of filesToMove to alias (rootFolder & ":" & thisItem)
如果您的Excel文件包含没有扩展名的文件名(仅可见名称),则可能会出现问题。
答案 1 :(得分:0)
您还有别名问题。所以我更新你的脚本,它现在正在为我工作(当然,我改变了路径以匹配我的用户/文件夹名称进行测试,但我将它们设置回来)
tell application "Microsoft Excel"
tell active sheet
set fileList to value of used range
tell used range
set rc to count of rows
end tell
end tell
end tell
set rootFolder to "Users:aldoopenhouse:Desktop:EN ATTENTE:test cahier de details:Master Detail Book:PDF"
set filesToMove to {}
repeat with thisItem in fileList
try
set end of filesToMove to (rootFolder & ":" & thisItem) as alias
on error
display dialog "File " & thisItem & " is not in the folder"
end try
end repeat
tell application "Finder"
move filesToMove to folder (("Users:aldoopenhouse:Desktop:EN ATTENTE:test cahier de details:*RESULT") as alias)
end tell
我简化了始终使用Finder表单的路径。
上次评论,我不喜欢文件夹 RESULT。我建议永远不要使用" "等特殊字符。在文件夹/文件名中。特别是" *"这是Unix命令中的通用字符!
答案 2 :(得分:0)
主要问题是used range
中的Excel
返回一个嵌套列表,以获取内部项目需要第二个重复循环。
Finder期望HFS路径(冒号分隔),这是获取当前桌面的HFS路径的最简单方法是
path to desktop as text
试试这个
tell application "Microsoft Excel"
tell active sheet
tell used range
set usedRange to value
set rc to count of rows
end tell
end tell
end tell
set baseFolder to (path to desktop as text) & "EN ATTENTE:test cahier de details:"
set rootFolder to baseFolder & "Master Detail Book:PDF:"
set filesToMove to {}
repeat with fileList in usedRange
repeat with thisItem in fileList
try
set end of filesToMove to alias (rootFolder & thisItem)
on error
display dialog "File " & thisItem & " is not in the folder"
end try
end repeat
end repeat
tell application "Finder"
move filesToMove to folder (baseFolder & "*RESULT:")
end tell