Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to compare two variable with nested for loop  (Read 3652 times)

0 Members and 1 Guest are viewing this topic.

yu262691

  • Guest
how to compare two variable with nested for loop
« on: January 11, 2008, 08:29:00 AM »
hi all

I need to design a batch file. this file will compare two dirctories. One named "script" and contains script files with .oam extension. The oter named "jobs" and contains subfolders.

If the a subfolder names in "jobs" is as same as a script name in "script", then delete it.

I have this code

@echo off

set sdir=c:\script
set jdir=c:\jobs

dir /a:-d /b %sdir% > slist.txt
dir /a:d /b %jdir% > dlist.txt

for /f %%x in (c:\slist.txt) do for /f %%y in (c:\dlist.txt) ...


In the nested for look I want to compare %%x and %%y+".oam". If they are same, I will delete %jdir%+"\"+%%y .

I dont know if my logic or designing is correct or not. please give me any suggestion.
« Last Edit: January 11, 2008, 08:46:06 AM by yu262691 »

yu262691

  • Guest
Re: how to compare two variable with nested for loop
« Reply #1 on: January 11, 2008, 09:00:20 AM »
figured it out


@echo off

set sdir=c:\script
set jdir=c:\jobs

dir /a:-d /b %sdir% > slist.txt
dir /a:d /b %jdir% > dlist.txt

for /f %%x in (c:\slist.txt) do for /f %%y in (c:\dlist.txt) do if %%x==%%y.oam rmdir /q %jdir%\%%y