How to give folder inside for loop in a batch

January 3, 2011 at 06:57:04
Specs: Windows XP
Hi

I have below batch file which search all the files in current folder for "error" keyword.for this i need to keep batch file in the same folder. But I donot want to keep the file in the same folder. I want to keep batch file on desktop and on executing it should search for the files in some other folder path. So i need change in for loop of below. please correct the below batch file and give me a solution

@echo off
for /f "tokens=* delims= " %%a in ('dir/b *.log') do (
find "Error " < %%a >> Error.txt
)



See More: How to give folder inside for loop in a batch

Report •


#1
January 3, 2011 at 11:06:04
Give the path @ this part:

dir C:\WINDOWS /b *.log

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#2
January 3, 2011 at 12:23:34
Isn't it...

dir C:\WINDOWS\*.LOG /b

also might want to add a /s to search subdirectories too.


Report •

#3
January 3, 2011 at 12:26:20
Doesnt matter where you place the options, begin or end.

Happy is ONE who says I am an OttoMAN.


Report •

Related Solutions

#4
January 5, 2011 at 04:01:49
No. i changed like u said. but it is not working. on executing batch file i am not getting any output file error.txt

Report •

#5
January 5, 2011 at 04:34:48
So you dont have any files containing "Error" in that directory(s).

And your script wont make the file 'Error.txt'.

Happy is ONE who says I am an OttoMAN.


Report •

#6
January 5, 2011 at 04:47:45
No. there are so many errors in the files which are in directories. But still it is not working. i tried keeping folder in many places. and i have kept batch file on desktop and executing. but not coming output file. Please can you verify again.

Report •

#7
January 5, 2011 at 09:54:13
Ooh, you're not executing the batch-script in the same directory(s)..

As already I said, give the path..?

If you execute the script from the desktop, without given a path, the dir /b/s command will look all sub-directory's under DESKTOP folder.

C:\Documents and Settings\Name\Desktop\YOUR-SCRIPT.bat

The script will look all directory's under Desktop, and doesnt find anything such as "Error" in any .log files.

Given path = C:\

@echo off
for /f "tokens=* delims= " %%a in ('dir /b/s C:\*.log') do (
find "Error " < %%a >> Error.txt
)
pause
exit

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#8
January 5, 2011 at 20:08:28
Ya. I have kept the batch file on desktop and my required folder to search is not under desktop. it is sme other drive. for ex : batch file is in desktop C:\ drive
and folder to search for log files error is in D:\sga\gre\ drive.


Report •

#9
January 5, 2011 at 20:11:27
and i am giving the complete D:\ drive path where my log files are situated. But still am unable to get output

Report •


Ask Question