Mac Extract Files From Multiple Folders

Prompting for Files or Folders

It’s generally good practice to avoid hard-coding file and folder paths in a script. Prompting the user to select files and folders makes for a more dynamic script that won’t break when paths change.

Prompting for a File

Use the Standard Additions scripting addition’s choose file command to prompt the user to select a file. Listing 26-1 and Listing 26-2 demonstrate how to use this command to display the simple file selection dialog with a custom prompt shown in Figure 26-1.

APPLESCRIPT

  • In the Move Items dialog, select the folder where you want to move all the files. To create a new folder, click the Make New Folder button and give the folder name accordingly. Once selected the folder, click Move. This moves all the files recursively from the multiple sub-folders to the destination folder chosen. Method 4: Using 7-Zip.
  • Use Power Query to combine multiple files with the same schema stored in a single folder into one table. For example, each month you want to combine budget workbooks from multiple departments, where the columns are the same, but the number of rows and values differ in each workbook.
  • OS X Technologies:: Sync Files And Folders Between Multiple Macs? Applications:: Batch Extract Multiple Archives With Password? ITunes:: Create Folders On One IPad And Sync The Folders To Multiple IPads? OS X:: How To Extract.RAR Files On A Mac? Software:: Extract Win - Rar Files In MAC? OS X:: On An Drive, Have Multiple Folders And Sub.
Listing 26-1AppleScript: Prompting for a file

Keep all of the files you want to add to your ZIP archive in a single folder. Open the folder containing your files in Finder. Select the files you want to add to the ZIP archive, right-click on any one file, and select Compress X Items (where X is the number of items you’ve selected). MacOS will create a ZIP file with all your selected files.

  1. set theDocument to choose file with prompt 'Please select a document to process:'
  2. --> Result: alias 'Macintosh HD:Users:yourUserName:Documents:ImportantDoc.pages'

JAVASCRIPT

Listing 26-2JavaScript: Prompting for a file
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var document = app.chooseFile({
  4. withPrompt: 'Please select a document to process:'
  5. })
  6. document
  7. // Result: Path('/Users/yourUserName/Documents/ImportantDoc.pages')

Prompting for a Specific Type of File

If your script requires specific types of files for processing, you can use the choose file command’s optional of type parameter to provide a list of acceptable types. Types may be specified as extension strings without the leading period (such as 'jpg' or 'png') or as uniform type identifiers (such as 'public.image' or 'com.apple.iwork.pages.sffpages'). Listing 26-3 and Listing 26-4 show how to prompt for an image.

APPLESCRIPT

Listing 26-3AppleScript: Prompting for an image
  1. set theImage to choose file with prompt 'Please select an image to process:' of type {'public.image'}
  2. --> Result: alias 'Macintosh HD:Users:yourUserName:Pictures:IMG_0024.jpg'

JAVASCRIPT

Listing 26-4JavaScript: Prompting for an image
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var image = app.chooseFile({
  4. withPrompt: 'Please select an image to process:',
  5. ofType: ['public.image']
  6. })
  7. image
  8. // Result: Path('/Users/yourUserName/Pictures/IMG_0024.jpg')

Prompting for Multiple Files

To let the user choose more than one file, include the choose file command’s optional multiple selections allowed parameter. Listing 26-5 and Listing 26-6 display a prompt asking for multiple images, as shown in Figure 26-2.

APPLESCRIPT

Listing 26-5AppleScript: Prompting for multiple images
  1. set theImages to choose file with prompt 'Please select some images to process:' of type {'public.image'} with multiple selections allowed
  2. --> Result: {alias 'Macintosh HD:Users:yourUserName:Pictures:IMG_0024.jpg', alias 'Macintosh HD:Users:yourUserName:Pictures:IMG_0025.jpg', alias 'Macintosh HD:Users:yourUserName:Pictures:IMG_0026.jpg'}

JAVASCRIPT

Listing 26-6JavaScript: Prompting for multiple images
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var images = app.chooseFile({
  4. withPrompt: 'Please select some images to process:',
  5. ofType: ['public.image'],
  6. multipleSelectionsAllowed: true
  7. })
  8. images
  9. // Result: [Path('/Users/yourUserName/Pictures/IMG_0024.jpg'), Path('/Users/yourUserName/Pictures/IMG_0025.jpg'), Path('/Users/yourUserName/Pictures/IMG_0026.jpg')]

Prompting for a Folder

Use the Standard Additions scripting addition’s choose folder command to prompt the user to select a folder, such as an output folder or folder of images to process. Listing 26-7 and Listing 26-8 demonstrate how to use this command to display the simple folder selection dialog with a custom prompt shown in Figure 26-3.

APPLESCRIPT

Listing 26-7AppleScript: Prompting for a folder
  1. set theOutputFolder to choose folder with prompt 'Please select an output folder:'
  2. --> Result: alias 'Macintosh HD:Users:yourUserName:Desktop:'

JAVASCRIPT

Listing 26-8JavaScript: Prompting for a folder
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var outputFolder = app.chooseFolder({
  4. withPrompt: 'Please select an output folder:'
  5. })
  6. outputFolder
  7. // Result: Path('/Users/yourUserName/Desktop')

Prompting for Multiple Folders

To let the user choose more than one folder, include the choose folder command’s optional multiple selections allowed parameter, as shown in Listing 26-9 and Listing 26-10.

APPLESCRIPT

Listing 26-9AppleScript: Prompting for multiple folders
  1. set theFoldersToProcess to choose folder with prompt 'Please select the folders containing images to process:' with multiple selections allowed
  2. --> Result: {alias 'Macintosh HD:Users:yourUserName:Desktop:', alias 'Macintosh HD:Users:yourUserName:Documents:'}

JAVASCRIPT

Listing 26-10JavaScript: Prompting for multiple folders

Extract Files From Multiple Folders

  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var foldersToProcess = app.chooseFolder({
  4. withPrompt: 'Please select an output folder:',
  5. multipleSelectionsAllowed: true
  6. })
  7. foldersToProcess
  8. // Result: [Path('/Users/yourUserName/Desktop'), Path('/Users/yourUserName/Documents')]

Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-06-13

December 06, 2019Nicole Jones

By creating a zip file on Mac, you can compress a single file, multiple files, or an entire folder into an archive .zip. Both Mac OS X and macOS operating systems have the built-in compression systems. Thus, you can zip and unzip files on Mac without installing extra software.

Zip files take less storage space on Mac. Moreover, you can share the same content with less time by compressing zip files. Many people prefer to zip files to reduce the email-transmission time. By the way, you can upload more files as email attachments without the space limit.

If you are not familiar with zipping and unzipping files on Mac, you can refer to the following paragraphs. This article introduces the detailed steps to create a zip archive in different cases. You can also unarchive zip files to extract whatever you need.

  • Part 1: What Is a Zip File on Mac
  • Part 2: How to Zip a File on Mac
  • Part 3: How to Unzip a File on Mac
  • Part 4: Store Too Many Files on Mac? Try This Powerful Mac Cleaner

Part 1: What Is a Zip File on Mac

Zip is an archive file format created by Phil Katz and PKWARE in 1989. It is a standard format designed for lossless data compression. When you create a zip file, the filename extension is .zip or .zip (newer compression algorithms). A zip file contains one or more files under the zip compression. You can set password protection when you zip a file on Mac.

You may also see rar files in many situations. What’s the difference between zip and rar? Well, the rar format was released in 1993 as a proprietary archive file format. In the zip VS rar round, zip has the better popularity than rar format. You need to install WinRAR to open rar files. But if you want to open zip files on Mac, you can solve the problem with simple clicks easily.

Part 2: How to Zip a File on Mac

There is a pre-installed tool named “Archive Utility”. You can make zip files on Mac directly with the help of Archive Utility. Of course, you can also type command lines to compress a zip file on Mac.

Way 1: How to Create a Zip File on Mac

Open Finder on Mac. Choose the file or folder you want to zip.
Select “Compress ** Items” from the right-click menu.
You can see a zipped file in the same destination place.

Way 2: How to Compress a Folder as ZIP on Mac

In the Finder, create a new folder. You can gather all files you want to compress into this folder.
Right-click on this newly created folder.
Choose “Compress **” to make a Zip file on Mac. You can also choose “Compress **” from the “File” drop-down list instead.

Way 3: How to Zip Files on Mac with Terminal

Run Finder and click “Applications” in the left pane.
Open the “Utilities” folder, you can find and open Terminal app on Mac quickly.
Type “zip archive.zip <filename>” and press “Enter” to create a zip file on Mac.
Alternatively, you can drag and drop files inside the Terminal to archive a zip file too.

Way 4: How to Password Protect a Zip File on Mac

Choose the file and right click on it. Select “Compress **” to zip a file.
Enter “Terminal” in Finder to quickly launch Terminal.

Batch Extract Files From Folders

Type “zip -er archive_name target_folder” in the Terminal window.
Type the password and repeat it for verification in the popping-up window.
Press “Enter” to create a password protect zip file on Mac.

Part 3: How to Unzip a File on Mac

If you download files from some online sites, you can find that the downloaded files are archived as zip files too. How to unzip files on Mac to decompress them? You can get the answer here.

Way 1: How to Open Zip Files on Mac

Head to the destination folder that contains your zipped file.
The Archive Utility feature is integrated into Mac by default. You can double-click on this zipped file to unzip it.
Thus, you can see a new folder appear with the same name of the zipped file.

Way 2: How to Unzip Files to the Same Directory on Mac

Navigate to the zipped file, like desktop, downloads or elsewhere.
You can choose one or more zipped files.
Choose “Open” to open a zipped file on Mac.

Way 3: How to Unzip a Zip File with Terminal on Mac

Run the Terminal application. You can find it by Finder > Applications > Utilities > Terminal.
Move the zipped file to the desktop. If not, you need to type the location in Terminal too.
Type “unzip archive.zip”. Press “Enter” to unzip a zip file on Mac.

Part 4: Store Too Many Files on Mac? Try This Powerful Mac Cleaner

How To Extract Multiple Folders

Though you can compress large files by zipping, those files still exist in your storage space. As time goes by, more and more zipped files will take place your limited storage space. You may forget those zipped files without opening for months. Well, why not clean up your Mac with Aiseesoft Mac Cleaner to get more free space? You can delete unneeded, large and old files selectively. The smart preview window can help you figure out whether you want to delete the junk file or not.

By the way, there is a built-in archiver. You can decompress 7Z and RAR files in one click. It is also supported to unzip GZ files on Mac here. You can uninstall apps, clean up cookies, encrypt files, manage Microsoft documents and do more changes within Mac Cleaner. It is more than a simple Mac cleaning software.

  • Scan large & old files, worthless files/cache/logs and other unneeded files.
  • Get smart filters for quick preview.
  • Quickly remove large & old files by months you did not open or the file size.
  • Compress files or extract files from 7z and RAR.
  • Safely delete large zipped files and other worthless files in one click.
Free download, install and launch Mac Cleaner. You can check the system status of your Mac in the “Status” section, including CPU, memory and disk.
Click “Large & Old Files” in the “Cleaner” section. Click “Scan” to find out all large files and folders on Mac you may not notice in seconds.
Click “View” to check the scanning result. You can see the large and old Mac files are classified into categories, including “> 100 MB”, “5 MB to 100 MB”, “> 1 Year” and “> 30 days”. Choose the term to get your zipped files based on your need.
You can see the exact file size of each file. Click the “Preview” icon to get a popping-up window. You can click “Uncompress” on the top right corner to unzip a file on Mac quickly. You can also click the “Folder” icon to navigate to its destination folder in one click.
Mark before the zipped files you want to delete. At last, click “Clean” to delete the selected files.

Note: You can compress any file or folder as a RAR file by using its “Unarchiver”. After adding your files, you can click the “Compress” or “Decompress” icon to extract and compress files on Mac. Thus, you can open any RAR file directly.

That’s all about how to Zip and Unzip a file on Mac. You can compress any photo, video, image, audio and more into a Zip file. Of course, you can open a zip file with the above steps easily. If your computer is still short of space after zipping files and folders, you can use Mac Cleaner to quickly delete downloads on Mac and compress/extract RAR files. The built-in duplicate finder, unarchiver and many other functions are also worth to try.

What do you think of this post?

Mac Extract Files From Multiple Folders File

Extract

Excellent

Rating: 4.7 / 5 (based on 126 votes)Follow Us on

  • What Does Encrypt SD Card Mean and How to Encrypt SD Card/USB Flash Drive

    What does encrypt SD card mean? How to encrypt SD card to better protect privacy? How to access and recover data from an encrypted SD card or USB flash drive? All your questions will be answered here.

  • Step-by-Step Guide (with Images) to Encrypt and Recover Excel 2007/2013/2010/2016/2019

    This tutorial shows you how to encrypt your Excel file to protect your worksheet and restore the file without password, even it is deleted or lost, and you could still restore it in this page.

  • How to Get Rid of Protection of Encrypted iTunes Backups (with/without Password)

    You are able to remove the protection of encrypted iTunes backups for erasing data permanently from iPhone, iPad and iPod, even if you forgot the password.