VideoHelp Forum




+ Reply to Thread
Results 1 to 4 of 4
  1. 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:
    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
    Tried this, same result:
    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
    If I simply put:
    Code:
    set filepath="%~1"
    echo %filepath%
    pause
    with a test file named “12345,6789.txt" on a volume with letter W: I get:
    "W:\12345"
    Quote Quote  
  2. this seams to work:
    Code:
    @echo off
    set "filepath=%*"
    echo %filepath%
    pause
    Quote Quote  
  3. Oh yes indeed, I had missed that:
    %* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...%255)
    This seems like a weird oversight for something that's been around for decades.

    The quotation marks don't seem to change the result, it's the same with:
    Code:
    set "filepath=%*"
    or:
    Code:
    set filepath=%*
    I also tested with:
    Code:
    set filepath=%1%2
    result: “W:\123456789.txt” – so the comma is missing, yet it does get the complete name with “set filepath=%*”, don't know why.
    Quote Quote  
  4. 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 ";".
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!