Gray_code_element

Monday, February 10, 2025

Extracting a series of zip files into folders with the names of each file

Batch File to Extract ZIP Files into Folders

Batch File to Extract ZIP Files into Folders

If you have multiple ZIP files in a folder and want to extract each one into its own folder with the same name as the ZIP file, you can use a batch script.

Method 1: Using Windows tar (Windows 10+)

Create a batch file and paste the following code:


    @echo off
    setlocal enabledelayedexpansion
    for %%F in (*.zip) do (
        set "foldername=%%~nF"
        mkdir "!foldername!"
        tar -xf "%%F" -C "!foldername!"
    )
    echo Extraction complete!
    pause
    

Steps:

  • Save the file as extract_all.bat in the folder containing your ZIP files.
  • Double-click the batch file to extract each ZIP file into a folder named after the ZIP filename.

Method 2: Using 7-Zip (More Reliable)

Prerequisite: Install 7-Zip and ensure it’s added to the system path or use the full path to 7z.exe.


    @echo off
    setlocal enabledelayedexpansion
    for %%F in (*.zip) do (
        set "foldername=%%~nF"
        mkdir "!foldername!"
        "C:\Program Files\7-Zip\7z.exe" x "%%F" -o"!foldername!" -y
    )
    echo Extraction complete!
    pause
    

Steps:

  • Save as extract_all.bat in the folder containing the ZIP files.
  • Run the batch file.

How It Works

  • for %%F in (*.zip) do → Loops through all .zip files in the folder.
  • set "foldername=%%~nF" → Extracts the filename (without extension).
  • mkdir "!foldername!" → Creates a folder with the same name.
  • tar -xf or 7z.exe x → Extracts the ZIP file into the created folder.

Would you like any modifications, such as handling subdirectories or logging extraction results? Let me know in the comments!

No comments:

Post a Comment

SVG: Two arrows with text on the ends

Example of Two arrows with text at the head of the arrow: Arrow with Text SVG Using Markers and Text tags In this tutoria...