使用applescript zip 文件夹

标签 zip applescript

我有这个applescript,它接受所选项目并压缩该文件/文件夹并使用名称作为zip名称。我遇到的问题是,当我解压缩 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

最佳答案

将 -j 开关添加到您的 zip 命令。换句话说,将“结束告诉”之前脚本的最后一行更改为:

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

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

关于使用applescript zip 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4909337/

相关文章:

Javascript/Html5 从 url 下载 zip

python - 在 Python 中循环压缩多个列表

zip - TeamCity:将附加日志添加到工件 zip 文件中

http - 如何解压十六进制形式的zlib数据?

osx-snow-leopard - 如何从 AppleScript 制作可执行程序

objective-c - Cocoa/Objective-c 'system();' 表现得很奇怪

java - Web 抓取到 applescript 变量中

.net - 使用 .NET 读取压缩的 xml

excel - AppleScriptTask 命令在 Excel 2016 for Mac VBA 中不起作用

applescript - 用applescript打开程序