【问题标题】:applescript to move files from folder A to folder B with excel list使用excel列表将文件从文件夹A移动到文件夹B的applescript
【发布时间】:2015-12-23 16:13:21
【问题描述】:

我有一个 PDF 文件夹,大约 650 个。我有一个包含 PDF 列表的 excel 列表,我必须将它们合并到一个 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 不在文件夹中

我做错了什么?

【问题讨论】:

    标签: excel applescript


    【解决方案1】:

    我假设您的文件夹是文件夹“Master Detail Book”中的“PDF”。连接 rootFolder 和 ThisItem 时,缺少分隔符“:”。

    您尝试在 filestoMove 末尾添加的是“Users:aldoopenhouse:Desktop:EN ATTENTE:test cahier de details:Master Detail Book:PDFthisitem”

    应该是“Users:aldoopenhouse:Desktop:EN ATTENTE:test cahier de details:Master Detail Book:PDF:thisitem”(添加了“:”)

    那么指令应该是:

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

    此外,如果您的 Excel 文件包含不带扩展名的文件名(仅可见名称),您也可能会遇到问题。

    【讨论】:

    • 我的 Excel 文件包含文件名 + 扩展名,我在此处发布之前修复了该问题。至于其余的,我仍然得到相同的味精。这是使用“/”而不是“:”的问题吗?
    【解决方案2】:

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

    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 命令中的通用字符!

    【讨论】:

      【解决方案3】:

      主要问题是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
      

      【讨论】:

        猜你喜欢
        • 2011-07-22
        • 1970-01-01
        • 1970-01-01
        • 2016-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多