Hi, I'm trying to create a batch file where I loop through a directory of audio files to create a variable holding all filenames wrapped in double quotes. I then pass this variable to foobar2000 to do some tagging.
The problem is my audio files can contain ampersands and exclamation marks.
For example, here's what that directory could look like:
Code: Select all
01. Some track.mp3
02. Some track & stuff.mp3
03. Some other track!.mp3
I would loop through this directory to create a variable containing the following:
Code: Select all
"01. Some track.mp3" "02. Some track & stuff.mp3" "03. Some other track!.mp3"
Here's what I have so far for my batch file:
Code: Select all
setlocal EnableDelayedExpansion
set tracks=
for /r %%i in (*.mp3) do (
set tracks=!tracks! "%%i"
)
:: Tag with foobar2000!
c:\apps\foobar2000\foobar2000.exe /tag:GUESS:"%%TRACKNUMBER%%. %%TITLE%%":%%_FILENAME%% %tracks%
endlocal
If I echo %tracks% after the for loop, files with exclamation marks will have the exclamation mark stripped. For example, "03. Some other track!.mp3" will become "03. Some other track.mp3" which is wrong. I know the issue is probably due to how I'm using delayed expansion with double quotes. Is there anyway I can get this batch file to work with both ampersands and exclamation marks?
Thanks so much for any help!