I've made a few .bat scripts to rename or compress files dragged-and-dropped onto them. They work with most files which have no non-ASCII characters, but they fail in one particular case: files with a name that has a comma but no space. Apparently, because there's no space, the variable (or rather the argument) is expanded with no quotation marks, and then the comma is interpreted as a delimiter. Is there any workaround?
Example:
Tried this, same result:Code:chcp 1252 set filepath=%~1 FOR /F "delims=\" %%L in ("%filepath%") DO set letter=%%L FOR %%F in ("%filepath%") DO ( set drive=%%~dF set filename=%%~nxF ) FOR /F "tokens=1,2,3,4,5 delims=/: " %%T in ("%~t1") DO set filedate=%%V%%U%%T%%W%%X %drive% 7z a -mx=7 -md=256m -mtc=on -mta=on "%filename% [%filedate%].7z" %1 pause
If I simply put:Code:chcp 1252 set filepath="%~1" FOR %%F in (%filepath%) DO ( set drive=%%~dF set filename=%%~nxF ) FOR /F "tokens=1,2,3,4,5 delims=/: " %%T in ("%~t1") DO set filedate=%%V%%U%%T%%W%%X %drive% 7z a -mx=7 -md=256m -mtc=on -mta=on "%filename% [%filedate%].7z" %filepath% pause
with a test file named “12345,6789.txt" on a volume with letter W: I get:Code:set filepath="%~1" echo %filepath% pause
"W:\12345"
+ Reply to Thread
Results 1 to 4 of 4
-
-
Oh yes indeed, I had missed that:
This seems like a weird oversight for something that's been around for decades.%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...%255)
The quotation marks don't seem to change the result, it's the same with:
or:Code:set "filepath=%*"
I also tested with:Code:set filepath=%*
result: “W:\123456789.txt” – so the comma is missing, yet it does get the complete name with “set filepath=%*”, don't know why.Code:set filepath=%1%2
-
Yeah, when there is something not possible to do in windows batch, there is a hack that fixes it. I did not know it either , I had to googled it.
That delimiter, besides "," suppose to be also "=" and ";".
Similar Threads
-
Background expansion
By Ciaka in forum EditingReplies: 1Last Post: 13th Oct 2023, 08:09 -
batch to find filenames with comma?
By marcorocchini in forum Newbie / General discussionsReplies: 3Last Post: 10th Sep 2023, 19:27 -
What's wrong with this video, Windows 11/macOS = NO, Android = Yes
By tigerb in forum Newbie / General discussionsReplies: 16Last Post: 13th Sep 2022, 20:35 -
chapters names
By maudit in forum Blu-ray RippingReplies: 0Last Post: 28th Dec 2021, 02:30 -
What can be so wrong that a Windows 10 Reinstallation hasn't fixed the issu
By kanamit in forum ComputerReplies: 20Last Post: 15th Nov 2021, 06:16



Quote