使用 applescript 压缩 zip 文件夹

发布于 2024-10-15 19:19:31 字数 650 浏览 5 评论 0原文

我有这个 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

I have this applescript that takes the selected item and zips that file/folder and uses the name as the zip name. The problem I have is when I unzip the zip it makes it has a folder structure all of the path from User on up.
Like this:

Users:
   username:
      folder:
           folder:

I would just like it to be :

folder:

Here is the code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜味拾荒者 2024-10-22 19:19:31

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

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

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

Add a -j switch to your zip command. In other words, change the last line of your script before "end tell" to:

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

That should tell the zip command to "junk" the path to whatever you're trying to compress when it makes the directory structure for the zip file.

凡尘雨 2024-10-22 19:19:31
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文