需求:编写Windows批处理脚本实现每500个通话录音打包为Zip
Auto-Batch Call Recordings into Zip Files (500 Files Per Zip)
I’ve run into this exact FTP transfer issue before—large single zips often fail due to server limits or bandwidth constraints. Here’s a reliable batch script that’ll automatically split your call recordings into manageable 500-file zips, which should resolve the transfer failures your vendor flagged.
The Script
First, make sure you have 7-Zip installed (it’s free and perfect for batch zipping). You can either add its installation path to your system PATH variable, or replace the zip_exe value below with the full path to 7z.exe (e.g., "C:\Program Files\7-Zip\7z.exe").
@echo off setlocal enabledelayedexpansion :: Configure these variables to match your setup set "source_dir=C:\Path\To\Your\Call\Recordings" set "zip_exe=7z.exe" set "files_per_zip=500" set "zip_prefix=CallRecordings_Batch_" :: Initialize counters and temp file set "file_count=0" set "batch_num=1" set "temp_list=temp_batch_files.txt" del /f /q "%temp_list%" 2>nul echo Starting batch processing... echo. :: Loop through all recording files (adjust wildcard to match your file type: *.wav, *.mp3, etc.) for %%f in ("%source_dir%\*.wav") do ( :: Add current file to the temporary batch list echo "%%~ff">>"%temp_list%" set /a file_count+=1 :: Package the batch when we hit the 500-file limit if !file_count! equ %files_per_zip% ( echo Creating %zip_prefix%!batch_num!.zip... "%zip_exe%" a -tzip "%source_dir%\%zip_prefix%!batch_num!.zip" @"%temp_list%" -mx5 :: Reset for next batch set "file_count=0" set /a batch_num+=1 del /f /q "%temp_list%" ) ) :: Handle any remaining files that didn't fill a full batch if !file_count! gtr 0 ( echo Creating %zip_prefix%!batch_num!.zip with remaining !file_count! files... "%zip_exe%" a -tzip "%source_dir%\%zip_prefix%!batch_num!.zip" @"%temp_list%" -mx5 del /f /q "%temp_list%" ) echo. echo Batch processing complete! Created !batch_num! zip files. pause endlocal
Key Adjustments & Details
- File Type: Change
*.wavin theforloop to match your recording file extension (e.g.,*.mp3,*.flac). - Compression: The
-mx5flag uses moderate compression—swap it for-mx0(no compression, fastest) or-mx9(max compression, slowest) based on your priorities. - Zip Location: Zips are saved in the same folder as recordings. To use a separate folder, modify the zip path (e.g.,
"C:\Path\To\Zips\%zip_prefix%!batch_num!.zip"). - FTP Integration: Update your existing FTP script to loop through all
%zip_prefix%*.zipfiles instead of a single zip—this will send every batch automatically.
Important Notes
- Test First: Run the script on a copy of your recordings first to avoid accidental data loss.
- 7-Zip Path: If you don’t add 7-Zip to your system
PATH, use the full path to7z.exein thezip_exevariable. - Delayed Expansion: The
enabledelayedexpansionflag is critical—it lets the script update and read counters correctly during the loop.
内容的提问来源于stack exchange,提问作者Greg
相关产品推荐
相关产品推荐

