Condition „IF” with variable with white space

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ernest211
Posts: 6
Joined: 14 Jun 2010 06:20

Condition „IF” with variable with white space

#1 Post by ernest211 » 15 Jun 2010 03:23

I have folder with other folders and I want to do something with them but only with some of them.
I have loop which searching all folders, loop have also condition which checking if folder name is different then specified than do something.
Unfortunately some folder have white space in name and my condition doesn’t work
This is my script

Code: Select all

set name1=folder a1

for /f "delims=" %%a in ('dir /b/ad') do (   

 if not %%a==folder1 if not %%a==folder2 if not %%a==%name1% (   
   rem do something
 )
 
)


After when I added “if not %%a==%name1%” in condition all condition stop working because there is a problem with white space in folder name.
How to resolve this problem?

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Condition „IF” with variable with white space

#2 Post by amel27 » 15 Jun 2010 03:35

Code: Select all

set name1=folder a1

for /f "delims=" %%a in ('dir /b/ad') do (   
   if /i not "%%a"=="folder1" if /i not "%%a"=="folder2" if /i not "%%a"=="%name1%" (
      rem do something
   )
)

ernest211
Posts: 6
Joined: 14 Jun 2010 06:20

Re: Condition „IF” with variable with white space

#3 Post by ernest211 » 15 Jun 2010 04:23

It's working, thanks.

Post Reply