0

I can't seem to find how to do this simple task, and this is probably answered.

How does one add a string to a variable? such as set "FileNameAndPCName = Locker\ and add %COMPUTERNAME%" to the variable so it would become like, "Locker/Bill"?

Code:

@echo off
set FileNameAndPCName="Locker\" + "%COMPUTERNAME%"
echo %FileNameAndPCName%
pause
Compo
  • 36,585
  • 5
  • 27
  • 39

1 Answers1

0

Operations in batch is already string manipulation, therefore you don't need and can't use + to concatenate strings. Just type the whole string like this

set "FileNameAndPCName=Locker\%COMPUTERNAME%"

set FileNameAndPCName="Locker\" + "%COMPUTERNAME%" will set the variable %FileNameAndPCName% to "Locker\" + "%COMPUTERNAME%" literally (after substituting %COMPUTERNAME%. Quotes are not special in the set command. And it's also recommended to use the set "var=value" variant instead of set var=value to avoid unexpected trailing spaces at the end

phuclv
  • 37,963
  • 15
  • 156
  • 475