开发者

Converting and deleting audio files in multiple directories using batch for loop

开发者 https://www.devze.com 2023-01-16 02:31 出处:网络
I want to process multiple audio files. What I want to do is take .m4a files in directory and for each of one do this:

I want to process multiple audio files. What I want to do is take .m4a files in directory and for each of one do this:

  • faad (it converts the .m4p file to a .wave file but keeps the .m4p file)
  • oddenc on the new .wave file, this creates an .ogg file
  • del the .m4a file and the .wavefile.
  • Move to the next .m4a in the directory

Also 开发者_如何学PythonI need it to do it to multiple folders (recursively).

What i have works, but it's messy. If first goes through the folders and creates .wave and .ogg files everywhere. This means I suddenly have all the .m4ps .waves and .oggs in the same folders, before they get deleted. It uses lots of space and I think there must be a way of converting each file and deleting it as it goes along.

This is what I have so far:

>for /r %%i in (*.m4a) do faad "%%i"  
for /r %%i in (*.wav) do oggenc "%%i"  
for /r %%i in (*.m4a) do del "%%i"  
for /r %%i in (*.wav) do del "%%i" 

But I want something like:

>for /r %%i in (*.mpa) do faad "%%i" (*wav) do oggenc "%%i" (*m4a) do del "%%i" (*wav) do del "%%i"

Is there a way I could achieve that this works? Because the above code doesn't.


You might also consider using dir2ogg to simplify the process if you have Python installed. It might be a bit of a challenge to get the binaries it's dependent on installed in Windows, though.


You'll be wanting braces for multiple commands, and %~n to get the filename (without extension) from the parameter:

::: Please define folder to search in (recursively)
if "%~1"=="" findstr "^:::" "%~f0"&GOTO:EOF

for /f %%i in ('dir %1\*.mp4 /b/s') do (
  faad "%%i"
  oggenc "%%~di%%~pi%%~ni.wav"
  del "%%~ni.m4a"
  del "%%~di%%~pi%%~ni.wav"
)

This relies on faad turning filename.mp4 -> filename.wav

Update: You need to supply 1 command line argument - the folder to recursively search, that is, all subfolders will be checkd for mp4 files and processed.

0

精彩评论

暂无评论...
验证码 换一张
取 消