Space in a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Space in a variable

#1 Post by lalat06bag » 06 Apr 2018 08:02

@echo on &setlocal
setlocal enableDelayedExpansion
If "%computername%" == "DTC" (
SET NS=\\xx
SET OPSDIR=!NS!\ProAdmin
SET COGDIR=!NS!\CREM
)
set "list=%COGDIR%\Config\Copy_Daily_EMTS_Reporting.txt"
echo %list%
pause


Why the list shows a space after cogdir in list? How to remove that space?
it shows \\xx\CREM \Config\Copy_Daily_EMTS_Reporting.txt
Attachments
Capture.PNG
space
Capture.PNG (22.73 KiB) Viewed 5222 times

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Space in a variable

#2 Post by batnoob » 06 Apr 2018 08:35

1. use code tags to wrap your code [code]<your code>[/code]
2. i belive there is a space after "SET COGDIR=!NS!\CREM" (select it and you'll see)

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Space in a variable

#3 Post by ShadowThief » 06 Apr 2018 09:08

batnoob wrote:
06 Apr 2018 08:35
2. i belive there is a space after "SET COGDIR=!NS!\CREM" (select it and you'll see)
There is, indeed. A perfect example of why you should always use quotes.

lalat06bag
Posts: 51
Joined: 10 Jan 2018 15:21

Re: Space in a variable

#4 Post by lalat06bag » 06 Apr 2018 09:27

yeah, I see it now. quoted it and it is now resolved.

Thank you.

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Space in a variable

#5 Post by batnoob » 06 Apr 2018 09:37

you are very welcome

Post Reply