Ampersand and exclamation mark in concatenated variable
Posted: 2022-Dec-31, 8:30 pm
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.
For example, I'll have a variable that will end up like this:
I'm very close to achieving what I want, but I'm having a tiny issue with ampersands in the folder or filename. I've already read about escaping the variable, but wrapping the filename in double quotes is causing a bit of an issue.
Here's what I have so far:
I know the issue is with the call set "tracks=%%tracks%% "%%i"" line, but I'm not sure how to fix it.
Any help will be greatly appreciated. Thanks and Happy New Year!
For example, I'll have a variable that will end up like this:
Code: Select all
"01. Track 1.mp3" "02. Track 2.mp3" "03. Track 3.mp3"
Here's what I have so far:
Code: Select all
:: Loop through all files in folder for .mp3 files only
:: %1 is the directory filepath.
:: Then, concat all mp3s into a single line, delimited by double-quotes
set audio=%1\*.mp3
set tracks=
for /F "delims=" %%i in ('dir /s/b %audio%') do (
call set "tracks=%%tracks%% "%%i""
)
:: Tag with foobar2000!
c:\apps\foobar2000\foobar2000.exe /tag:GUESS:"%%TRACKNUMBER%%. %%TITLE%%":%%_FILENAME%% %tracks%
Any help will be greatly appreciated. Thanks and Happy New Year!