How to use & in SET function of Bat programming?

Viewed 55

I am having a folder on my *C:* drive Check & Fill. Check & Fill folder contains a file v.txt which contains version name. How can I open this file using BAT programming to get the version name?

SET "versionfolder=C:\Check ^& Fill\"
SET "filename=%versionfolder%v.txt"

For /f "skip=1 delims== tokens=2*" in ('find "ver" "%filename%"') do (
SET VersionName=%%i
)
Echo %VersionName%

File not found error is coming in the FOR statement.

1 Answers

corrections made:
no escape needed for & within double quot's.
added "" in set filename
added parameter %%i in for-loop before the in (syntax error)
added reset for variable VersionName.

SET "versionfolder=C:\Check & Fill"
SET "filename=%versionfolder%\v.txt"

SET "VersionName="
For /f "skip=1 delims== tokens=2*" %%i in ('find "ver" "%filename%"') do (
SET VersionName=%%i
)
Echo %VersionName%
Related