简体   繁体   中英

Batch convert .wav files to .mp3 files through sub-directories then delete the remaining .wav files

I work at a radio station where we audio log using a program called Skimmer Plus that creates multiple sub directories out of our parent directory "Air Check" and the directory tree looks like this (descending):

Air Check
Year (so right now it would be 2016)
Month (November)
Day (22)

And the .wav files are saved in the Day directory, but there are no files saved in any of the other directories, just in the "Day" directory.

What I am struggling with is first automatically converting the .wav files to .mp3 files. Right now I just use the lame dropper "lamedropXPd3-64.exe", but I also have "lame.exe" downloaded and available to use if that would make it easier. Here is the code I have attempted with the automatic conversion:

@echo off
PushD for %%i in (*.wav) do "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" -V 6 --vbr-old --resample 22.05 "%%i" "%%~ni.mp3" & PopD
pause

And the error message I get is: "The filename, directory name, or volume label syntax is incorrect."

So that is my first issue.

The second issue (deleting the leftover .wav files in order to save space) I'm a lot closer on getting to work. Here is my code:

@echo off
PushD "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" &&(forfiles -m *.wav* -d -0 -c "cmd /c del /s /q @path") & PopD
pause

And that works to delete all the files, but as you can see, it will only affect that day. I want it to work from this point right here:

@echo off
PushD "\\wideorbit.byui.edu\d\Radio Productions\Air Check\" &&(forfiles -m *.wav* -d -0 -c "cmd /c del /s /q @path") & PopD
pause

But when I try and run that, I get the following error message: "ERROR: no files found with the specified search criteria."

What could I change on both parts of the code to make them fully operable?

(Also, I put the @echo off and pause in there for ease in testing, I will be taking them out when I get a final program together).

Thank you!

@echo off
PushD
for %%i in (*.wav) do someexecutablenameherwouldbehelpfulIthink "\\wideorbit.byui.edu\d\Radio Productions\Air Check\2016\November\22" -V 6 --vbr-old --resample 22.05 "%%i" "%%~ni.mp3"
PopD
pause

To put some decent tips you got together, this batch will by default scan the current day folder for .wav files. But there are optional command line args to scan the whole tree down from Base through /FullScan or current /Year or /Month .

The Lame and Del commands are only Echoed as long as the two echo commands stay in the second last line.

:: Wav2mpg.cmd
@Echo off & SetLocal EnableExtensions EnableDelayedExpansion
Set Lame="X:\Path\to\your\lame.exe"
Set LameOpts= -V 6 --vbr-old --resample 22.05
Set "Base=\\wideorbit.byui.edu\d\Radio Productions\Air Check"

:: Get current Date
For /f "tokens=1-3 delims=.+-" %%A in (
  'wmic os get LocalDateTime^|findstr ^^[0-9]'
) do Set _DT=%%A
Set "year=%_DT:~0,4%"&Set "Month=%_DT:~4,2%"&Set "Day=%_DT:~6,2%"
:: Strip leading zero from Month, Get Monthname
set /a Mo=100%Month%%%100
For /f "tokens=%Mo%" %%A in (
  'echo/January February March April May June^
   July August September October November December'
) do set MonthName=%%A

If /i "%~1" Equ "/FullScan" Goto :Skipover
If /i "%~1" Equ "/Year"  Set Base=%Base%\%Year%
If /i "%~1" Equ "/Month" Set Base=%Base%\%Year%\%MonthName%
If /i "%~1" Equ "" Set Base=%Base%\%Year%\%MonthName%\%Day%

:skipover
PushD "%Base%" || (Echo couldn't pushd %Base%&Pause&Exit /B 1)
For /f  "delims=" %%A in (
  'Dir /B/S/A-D .\*.wav'
) Do Echo %Lame% %LameOpts% "%%~fA" "%%~dpnA.mp3" && Echo Del "%%~fA"
PopD

To convert all .wav files in your directory tree to .mp3 files, you could use the following code:

pushd "\\wideorbit.byui.edu\d\Radio Productions\Air Check" || exit /B 1
for /R %%F in ("*.wav") do (
    pushd "%%~dpF" && (
        lame -V 6 --vbr-old --resample 22.05 "%%~nxF" "%%~nF.mp3" && (
            del "%%~nxF"
        )
        popd
    )
)
popd

To convert .wav files of today (or, more precisely said, those with a modification date of today, without checking the parent directory name), you could use the following code:

pushd "\\wideorbit.byui.edu\d\Radio Productions\Air Check" || exit /B 1
for /F "delims=" %%F in ('
    forfiles /S /M "*.wav" /D +0 /C "cmd /C echo @path"
') do (
    pushd "%%~dpF" && (
        lame -V 6 --vbr-old --resample 22.05 "%%~nxF" "%%~nF.mp3" && (
            del "%%~nxF"
        )
        popd
    )
)
popd

Note that for both approaches, successfully converted .wav files are deleted afterwards.

can only recommend "EZ CD Audio Converter", using it for years, being very excited with, for converting (and also deleting in one run). Not expensive, worth every cent. There's a free 30days trial available.

For organizing, moving, tagging I recommend "mp3tag". Can work in batches and tag and move files. Great freeware, but for the full potential you have to learn the syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM