All articles

How to Zip Each File or Folder Separately on a Mac

· 6 min read

Ten client folders, and each client should get only theirs. A week of recordings to upload one by one. Old projects to archive, one ZIP each. Select them all in the Finder, choose Compress, and you get a single Archive.zip with everything inside.

The short answer:

  • The Finder can't make one archive per item. Compress the items one at a time, or use the Terminal loop below, which you can also turn into a Quick Action.
  • In Folia Files, select the items, right-click, point to Compress, and under Each Item Separately choose ZIP, 7Z, TAR.GZ or TAR.XZ. Each item gets its own archive, right next to it.

What the Finder's Compress does

Right-click a single item and choose Compress “Atlas”: you get one ZIP named after it, Atlas.zip for a folder, report.pdf.zip for a file. Select several items and the command becomes Compress 3 Items (or however many you selected). They all go into one archive called Archive.zip, in the same folder.

There is no setting to get one archive per item. You either compress them one by one, or you let a small script do it.

Zip each item separately in Terminal

macOS includes ditto, a copy tool that also makes ZIP archives the way the Finder does. A short loop runs it once for each item of a folder:

  1. Open Terminal (in Applications › Utilities).
  2. Type cd and a space, drag the folder that holds the items onto the Terminal window, and press ↩.
  3. Paste these lines and press ↩:
for item in ./*; do
  [[ "$item" == *.zip || -e "$item.zip" ]] && continue
  if [[ -d "$item" ]]; then
    ditto -c -k --sequesterRsrc --keepParent "$item" "$item.zip"
  else
    ditto -c -k --sequesterRsrc "$item" "$item.zip"
  fi
done

Every item of the folder now has its ZIP beside it: Atlas.zip next to the Atlas folder, report.pdf.zip next to report.pdf. Run it in a folder that holds only what you want to archive, since every file and folder in it gets an archive. What each part takes care of:

  • ./* goes through the items of the folder, leaving out hidden ones (names that start with a dot). The ./ in front keeps a name that starts with a dash from being read as an option.
  • The second line skips the ZIP files themselves and any item that already has its archive, so running the loop twice neither redoes nor overwrites anything.
  • A folder is archived with --keepParent, so it unzips as the folder itself. A file is archived on its own: with --keepParent, ditto would wrap it in a folder named after the one it sits in.
  • --sequesterRsrc keeps the Mac's extra file data in a __MACOSX folder inside the archive, as the Finder's ZIPs do.

Names with spaces or accents are no problem: every $item is in quotes.

The tar command of macOS writes the other formats. Replace the if … fi block with one of these lines, and .zip in the second line with the same extension:

  • TAR.GZ: tar -czf "$item.tar.gz" "$item"
  • TAR.XZ: tar -cJf "$item.tar.xz" "$item"
  • 7Z: tar --format 7zip -cf "$item.7z" "$item"

If you use Folia Files, right-click the background of the folder and choose Open in Terminal: the terminal opens in that folder, so you can skip the cd. The website edition also has Folia Files Terminal, which opens under the pane, as below.

The same loop run in the terminal under a Folia Files pane: the Atlas, Design and website folders each get their own ZIP

Turn the loop into a Quick Action

To keep it one right-click away in the Finder:

  1. Open Automator, choose File › New, select Quick Action and click Choose.
  2. In the bar at the top, set Workflow receives current to files or folders, and in to Finder.app.
  3. Drag the Run Shell Script action from the library into the workflow. Check that Shell says /bin/zsh, set Pass input to as arguments, and replace its text with the loop above, its first line changed to for item in "$@"; do (the items you right-clicked).
  4. Save it with ⌘S under a name such as "Zip Each Separately".

It now appears under Quick Actions when you right-click files in the Finder. Set to Finder.app, it stays out of the other apps' menus, for a reason explained in why your Automator Quick Action only shows up in the Finder (the website edition of Folia Files lists it anyway).

In Folia Files: Compress › Each Item Separately

Folia Files does it from its right-click menu, in every view:

  1. Select the items: ⌘-click or ⇧-click them, or press ⌘A for all.
  2. Right-click one of them and point to Compress.
  3. The four formats at the top make a single archive of the whole selection, Archive.zip, as the Finder does. Under Each Item Separately, the same four formats make one archive per item. That second part appears as soon as two or more items are selected.

The Compress submenu on three selected folders: ZIP, 7Z, TAR.GZ and TAR.XZ, then the same formats under Each Item Separately

What you get:

  • One archive next to each item, named after it: Atlas.zip, Design.zip… A file keeps its extension in the name, Notes.md.zip, as with the Finder.
  • Nothing replaced. If Atlas.zip is already there, the new one is called Atlas 2.zip.
  • Items from several folders. In the Tree view, you can select items in different subfolders: each archive lands next to its own item.
  • The new archives selected once they're made, ready to drag into an email, or onto a cloud or server folder open in the other pane.

Compress sits with the other archive and file tools of the right-click menu, described on the file tools page.

Follow, pause or cancel in Operations

Folia Files makes the archives one after the other, not all at once: several archivers running together would only fight over the disk. Each archive is a line in Operations, the toolbar button that also follows copies and moves (or Window › Operations in Progress, ⌃⌘O):

  • Compressing to .zip (or .7z, .tar.gz…), with a progress bar based on the size measured before starting, the name of the file being added, how much is done out of the total, the speed and the time left. The archives waiting their turn say Preparing….
  • The pause button stops the archiver where it is, and Resume picks up from there. The archives after it wait.
  • The ✕ button (Cancel) stops one archive. Each archive is written under a hidden name next to the items and only takes its real name once complete, so a cancelled one leaves nothing behind, and a half-written file never looks finished. The archives already made stay, and the others go on.

ZIP, 7Z, TAR.GZ or TAR.XZ?

  • ZIP opens with a double-click on a Mac or a Windows PC, with nothing to install. It's the one for clients, colleagues, and anyone whose computer you don't know.
  • 7Z usually comes out smaller than ZIP, mostly with documents, text and code. Not every computer opens it without an extra app, so keep it for people who have one, or for your own archives.
  • TAR.GZ is the habit of Linux servers and developers. It keeps Unix permissions and symbolic links as they are.
  • TAR.XZ is generally smaller than TAR.GZ, and slower to make.

Photos, videos and music are already compressed: no format makes them much smaller. Archive them to keep them together or to send them, not to save space.

Opening them again

In Folia Files, double-click a ZIP, 7Z or TAR archive and it opens in the pane like a folder, read-only; Extract Here unpacks it next to the archive, and Extract To into another folder. How to open a ZIP file without extracting it has the details.

In short

  • Finder: one Archive.zip for the whole selection, whatever you select.
  • Terminal: the ditto loop above, or tar for TAR.GZ, TAR.XZ and 7Z; the same loop fits in an Automator Quick Action.
  • Folia Files: Compress › Each Item Separately, then the format. One archive next to each item, followed in Operations, and nothing left behind if you cancel.