I have a batch script file that converts existing wav
files to Mono wav files to a created folder called "Mono"
CODE
@echo off && cd /d "%~dp0"
2>nul mkdir "Mono"
set "_sox=C:\Program Files (x86)\sox-14-4-2\sox.exe"
for %%i in ("*.wav") do "%_sox%" -S "%%~fi" "Mono\%%~ni.wav" channels 1
I have to place this .bat
file in the folder that I want converted. My folder structure is expanding and I have to go through each folder manually, place the .bat
file and run the script to get the resultant mono files.
Here is an example of my folder structure:
Main Folder
|
|______fold1
| |_____file1.wav
| |_____file2.wav
|
|______fold2
| |_____file1.wav
| |_____file2.wav
|
|______fold3
|_____file1.wav
|_____file2.wav
With the expanding folder structure, I wanted to place the .bat
file in the Main Folder, run the script, and the script will go through each subfolder, create the "Mono" folder in each subfolder and place the converted mono wav files in there. This should be the updated file structure with the converted mono files:
Main Folder
|
|______fold1
| |_____file1.wav
| |_____file2.wav
| |_____Mono
| |______file1.wav
| |______file2.wav
|______fold2
| |_____file1.wav
| |_____file2.wav
| |_____Mono
| |______file1.wav
| |______file2.wav
|______fold3
| |_____file1.wav
| |_____file2.wav
| |_____Mono
| |______file1.wav
| |______file2.wav
Please let me know how to modify the .bat
file to accomplish this task. Thanks!
CodePudding user response:
This is how I would do it:
@ECHO OFF
SET "_sox=C:\Program Files (x86)\sox-14-4-2\sox.exe"
FOR /F "usebackq delims=" %%A IN (`DIR /B "%~dp0"`) DO (
MKDIR "%~dp0\%%A\Mono" 2> NUL
FOR /F "usebackq delims=" %%B IN (`DIR /B "%~dp0\%%A\*.wav"`) DO (
"%_sox%" -S "%~dp0\%%A\%%B" "%~dp0\%%A\Mono\%%~nB.wav" channels 1
)
)
DIR /B
lists every file and folder within the specified folder.
For each folder it finds, it will create a Mono folder within it, and then run the sox command for each .wav
file found.
Hope this helps. Love your name btw