batch file: pass parameter with white spaces to function

Viewed 14495

I am using a batch file for backups. I pass the options to a function which calls the packaging executable. This works unless the parameters contain whitespaces. This is the relevant code:

SET TARGET="%SAVEDIR%\XP.User.Documents.rar"
SET FILES="%DIRUSER%\Eigene Dateien\*"      
SET EXLUCDE="%DIRUSER%\Documents\CDs" 
call:funcBackup %TARGET% %FILES% %EXLUCDE%

:funcBackup
    SET TARGET=%~1
    SET FILES=%~2
    SET EXCLUDE=%~3     
    echo."%PACKER% a -r -x"%EXCLUDE%" "%TARGET%" "%FILES%""
    ::call %PACKER% a -r -x"%EXCLUDE%" "%TARGET%" "%FILES%"
goto:eof

On XP(german version) %DIRUSER% expands to "Dokumente und Einstellungen"

In that case TARGET is correct, but FILES == "Dokumente" and EXCLUDE == "und", which means that the script fails because of the whitespaces in %DIRUSER%.

How can I fix this?

2 Answers
Related