Avatar of pphreadr
pphreadr
Flag for United States of America

asked on 

batch remove quotes from variables

I have had several instances where I need/want to create a variable by combining other variables. i.e. SET PathFile="%CurrentDir%%MyFile%"

I am looking for a way to strip the quotes (") from the variables so I can combine several and enclose all in a single set of quotes for use somewhere in the script. Same issue happens when I need to use an environment variable that has a space.

For some of my needs I have found a way to work around this issue. However I would really like to know if there is a way to do this.

@ECHO OFF
SET CurrentDir=c:\Users\Tony\Documents\Fort Worth ToDo\
SET MyFile=to do.txt
SET PathFile="%CurrentDir%%MyFile%"
ECHO the Directory is %CurrentDir%
ECHO the File is %MyFile%
ECHO the File - Path is %PathFile%
ECHO %ProgramFiles(x86)%
ECHO.
FOR /F "Tokens=*" %%A in ( 'TYPE "%PathFile%" ^| FINDSTR /V /C:"REM"' ) DO (
	REM ECHO %MyFile%
	ECHO %%A
	)

Open in new window


Results of above
the Directory is c:\Users\Tony\Documents\Fort Worth ToDo\
the File is to do.txt
the File - Path is "c:\Users\Tony\Documents\Fort Worth ToDo\to do.txt"
C:\Program Files (x86)




The system cannot find the file specified.
Error occurred while processing: c:\Users\Tony\Documents\Fort.
The system cannot find the file specified.
Error occurred while processing: Worth.
The system cannot find the path specified.
Windows OSMicrosoft Legacy OSWindows Batch

Avatar of undefined
Last Comment
Steve Knight

8/22/2022 - Mon