Issue with MakeAbsolute

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tho_gru
Posts: 1
Joined: 03 Apr 2022 19:37

Issue with MakeAbsolute

#1 Post by tho_gru » 03 Apr 2022 19:59

Hello Forum users,

I copied the batch function MakeAbsolute https://www.dostips.com/DtCodeCmdLib.php#MakeAbsolute and stored it in file MakeAbsolute-Original.cmd.

I called it from Test-Original.cmd containing the following code:

Code: Select all

set "testFilename=def.txt"
call MakeAbsolute-Original.cmd testFilename "C:\Program Files (x86)\Microsoft Visual Studio"
Both CMD files are stored in directory C:\xxx.


When running I get the output:

Code: Select all

C:\xxx>Test-Original.cmd

C:\xxx>set "testFilename=def.txt"

C:\xxx>call MakeAbsolute-Original.cmd testFilename "C:\Program Files (x86)\Microsoft Visual Studio"

C:\xxx>SETLOCAL ENABLEDELAYEDEXPANSION

C:\xxx>set "src=testFilename"

C:\xxx>if defined testFilename set "src=!testFilename!"

C:\xxx>set "bas=C:\Program Files (x86)\Microsoft Visual Studio"

C:\xxx>if not defined bas set "bas=C:\xxx"

C:\xxx>for /F "tokens=*" %a in ("C:\Program Files (x86)\Microsoft Visual Studio.\def.txt") do set "src=%~fa"

C:\xxx>set "src=C:\Program Files (x86)\Microsoft Visual Studio\def.txt"
"\Microsoft" kann syntaktisch an dieser Stelle nicht verarbeitet werden.

C:\xxx>    IF defined testFilename (SET testFilename=C:\Program Files (x86)\Microsoft Visual Studio\def.txt) ELSE ECHO.C:\Program Files (x86)\Microsoft Visual Studio\def.txt

C:\xxx>
CMD.EXE complains about a syntax error.


My system environment is:

Code: Select all

Windows version:   Microsoft Windows [Version 10.0.19044.1586]
Product name:      Windows 10 Pro
Processor arch:    AMD64 and 64 bit Windows

Date format:       dd/mm/yy =  04.04.2022
Time format:       24 hours =   3:24:09,29
Extensions:        system:Enabled   user:Enabled 
Delayed expansion: system:Disabled  user:Disabled
Locale name:       de-DE      Code Pages:   OEM 850     ANSI 1252
DIR  format:       31.03.2022  15:42     8.589.934.592 pagefile.sys
I think the error is related to the combination of (, ) and space characters "C:\Program Files (x86)\Microsoft Visual Studio". Unfortunatly this is the default installion path for Visual Studio. And therefore I would be really happy if you can help me to fix the issue.

Do you have any ideas?

Kind Regards
Thomas

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Issue with MakeAbsolute

#2 Post by aGerman » 04 Apr 2022 11:13

Turns out that the parentheses in the path make it fail. A quotet assignment at the end should avoid this problem.

Code: Select all

    IF defined %1 (SET "%~1=%src%") ELSE ECHO."%src%"
Steffen

Post Reply