Page 1 of 1

Condition „IF” with variable with white space

Posted: 15 Jun 2010 03:23
by ernest211
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?

Re: Condition „IF” with variable with white space

Posted: 15 Jun 2010 03:35
by amel27

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
   )
)

Re: Condition „IF” with variable with white space

Posted: 15 Jun 2010 04:23
by ernest211
It's working, thanks.