【问题标题】:zip folder using applescript使用applescript的zip文件夹
【发布时间】:2011-02-05 20:05:43
【问题描述】:

我有这个applescript,它采用选定的项目并压缩该文件/文件夹并将名称用作压缩名称。我遇到的问题是,当我解压缩 zip 文件时,它具有一个文件夹结构,所有从用户开始的路径。 像这样:

Users:
   username:
      folder:
           folder:

我希望它是:

folder:

代码如下:

tell application "Finder"
    set theItem to selection as alias
    set itemPath to quoted form of POSIX path of theItem
    set fileName to name of theItem
    set theFolder to POSIX path of (container of theItem as alias)
    set zipFile to quoted form of (theFolder & fileName & ".zip")
    do shell script "zip -r " & zipFile & " " & itemPath
end tell

【问题讨论】:

    标签: zip applescript


    【解决方案1】:

    在您的 zip 命令中添加 -j 开关。换句话说,将“end tell”之前脚本的最后一行更改为:

    do shell script "zip -jr " & zipFile & " " & itemPath
    

    这应该告诉 zip 命令在创建 zip 文件的目录结构时将路径“垃圾”到您尝试压缩的任何内容。

    【讨论】:

    • 如果你使用 -j,当你有两个同名文件时,你会得到一个错误。
    【解决方案2】:
    tell application "Finder"
        set theItems to selection
        repeat with _a from 1 to (count of theItems)
            set theItem to (item _a of theItems) as alias
            set itemPath to quoted form of POSIX path of theItem
            set fileName to name of theItem
            set theFolder to POSIX path of (container of theItem as alias)
            set zipFile to quoted form of (theFolder & fileName & ".zip")
            do shell script "zip -r " & zipFile & " " & itemPath
        end repeat
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      相关资源
      最近更新 更多