Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
applescript使用excel列表将文件从文件夹A移动到文件夹B_Excel_Applescript - Fatal编程技术网

applescript使用excel列表将文件从文件夹A移动到文件夹B

applescript使用excel列表将文件从文件夹A移动到文件夹B,excel,applescript,Excel,Applescript,我有一个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 en

我有一个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
此脚本始终会重新调用结果:
文件*********.pdf
不在文件夹中


我做错了什么?

我假设您的文件夹是“主详细信息手册”文件夹中的“PDF”。在连接rootFolder和ThisItem时,缺少分隔符“:”

您尝试在filestoMove末尾添加的内容是“用户:aldoopenhouse:桌面:EN ATTENTE:test cahier de details:Master Detail Book:PDFthisitem”

其中应该是“用户:OpenHouse:Desktop:EN ATTENTE:test cahier de details:Master Detail Book:PDF:thisitem”(添加了“:”)

那么说明应该是:

set end of filesToMove to alias (rootFolder & ":" & thisItem)

此外,如果Excel文件包含没有扩展名的文件名(仅可见名称),则可能会出现问题

您还存在别名问题。因此,我更新了您的脚本,它现在对我有效(当然,我更改了路径以匹配用于测试的用户/文件夹名称,但我将它们设置回原来的位置)

我简化了路径以始终使用Finder表单


最后一条评论,我不喜欢文件夹结果。我建议不要在文件夹/文件名中使用像“”这样的特殊字符。尤其是“*”,它是Unix命令中的通用字符

主要问题是
Excel
中的
used range
返回一个嵌套列表,要获取内部项,需要第二个重复循环

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

我的Excel文件包含文件名+扩展名,我在这里发布之前解决了这个问题。至于其余的,我仍然得到相同的味精。这是使用“/”而不是“:”的问题吗?
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