You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Server 2012 R2批量解压目录及子目录下特定命名Zip文件求助

Bulk Unzip dumpdata_yymm_as_tap.zip Files to Dedicated Folders

Hey there! Since you're new to PowerShell and batch scripts, let's walk through two easy-to-follow methods to handle your bulk unzipping task. Both will automatically find all your matching ZIP files and extract each to a unique target folder under f:\.


PowerShell handles spaces in file/folder names smoothly, making it a great choice here. Here's a script you can use right away:

# Set the root path where your ZIP files are stored
$sourceRoot = "Z:\abc"
# Set the root path for your target extraction folders
$targetRoot = "f:\"

# Find all ZIP files matching the pattern: dumpdata_yymm_as_tap.zip
$zipFiles = Get-ChildItem -Path $sourceRoot -Filter "dumpdata_*_as_tap.zip" -Recurse

# Loop through each ZIP file one by one
foreach ($zip in $zipFiles) {
    # Use the ZIP's base name (without .zip) as the target folder name
    $targetFolderName = $zip.BaseName
    # Keep the original subfolder structure (like data1/data2) in the target path
    $relativePath = $zip.DirectoryName.Substring($sourceRoot.Length)
    $targetFolder = Join-Path -Path $targetRoot -ChildPath "$relativePath\$targetFolderName"

    # Create the target folder if it doesn't exist yet
    if (-not (Test-Path -Path $targetFolder)) {
        New-Item -ItemType Directory -Path $targetFolder | Out-Null
    }

    # Extract the ZIP content to the target folder (overwrites existing files if present)
    Expand-Archive -Path $zip.FullName -DestinationPath $targetFolder -Force
    Write-Host "Extracted $($zip.Name) to $targetFolder"
}

How to use this:

  1. Open PowerShell (search for "PowerShell" in Windows Start menu)
  2. Copy-paste the script above, adjust $sourceRoot and $targetRoot if your paths are different
  3. Press Enter to run the script

Quick notes:

  • The -Force parameter will overwrite existing files in the target folder (remove it if you don't want this behavior)
  • Expand-Archive is built into PowerShell 5.1 and later (most modern Windows systems have this pre-installed)

Method 2: Batch Script (Using 7-Zip)

If you prefer batch scripts, you'll need 7-Zip installed (it's free and widely used for handling archives). First, install 7-Zip, then note its installation path (usually C:\Program Files\7-Zip\7z.exe).

Here's the batch script:

@echo off
setlocal enabledelayedexpansion

:: Set your source and target root paths
set "sourceRoot=Z:\abc"
set "targetRoot=f:\"
set "7zipPath=C:\Program Files\7-Zip\7z.exe"

:: Find all matching ZIP files recursively
for /r "%sourceRoot%" %%f in (dumpdata_*_as_tap.zip) do (
    :: Get the relative subfolder path from the source root
    set "relativeDir=%%~dpf"
    set "relativeDir=!relativeDir:%sourceRoot%=!"
    :: Get the ZIP file's base name (without .zip extension)
    set "folderName=%%~nf"
    :: Build the full target folder path
    set "targetFolder=%targetRoot%!relativeDir!!folderName!"

    :: Create the target folder if it doesn't exist
    if not exist "!targetFolder!" mkdir "!targetFolder!"

    :: Extract the ZIP file with 7-Zip (automatically confirms overwrite prompts)
    "%7zipPath%" x "%%f" -o"!targetFolder!" -y
    echo Extracted "%%~nxf" to "!targetFolder!"
)

endlocal
pause

How to use this:

  1. Open Notepad, copy-paste the script, adjust the paths (sourceRoot, targetRoot, 7zipPath) as needed
  2. Save the file with a .bat extension (e.g., BulkUnzip.bat)
  3. Double-click the .bat file to run it

Quick notes:

  • Replace 7zipPath with your actual 7-Zip installation path if it's different
  • The -y parameter skips overwrite confirmation prompts (remove it if you want to be asked before overwriting)

Beginner Pro Tips:

  • Always test with a small number of files first (copy a few ZIPs to a test folder and run the script there)
  • Make sure you have write permissions for the f:\ target directory
  • If you see errors, double-check the paths in the script for typos (especially spaces in folder names)

内容的提问来源于stack exchange,提问作者aksr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:50:20