Page 1 of 1

Batch file to find file in folder & subfolders

Posted: 27 Jul 2011 13:01
by Maheshp
Hi
i want batch file which will work like windows search
when i run the batch file
1.it will prompt for path
2. then search string (eg. sample workbook.xls) i will enter string sample
3.it will search for string on that path & save the results in excel file, mean ">" divert the results to excel file in same folder
4. excel file will contain all the results of search, it should contain path of file which is found
eg. c:\temp\sample.xls
c:\temp\temp2\sample workbook.xls
5.if not found then excel file results will be not found

i will appreciate any help on this.

Re: Batch file to find file in folder & subfolders

Posted: 28 Jul 2011 03:23
by renzlo
try this

Code: Select all

@echo off

dir /s /b > source

set /p "str2find=Search for: "
findstr /s /i "%str2find" source && findstr /i "%str2find" source >> results.csv || echo file not found >> results.csv

del /f /q source
exit /b

Re: Batch file to find file in folder & subfolders

Posted: 31 Jul 2011 11:30
by Maheshp
Thank u so much Renzlo !

this batch do execute, but when i enter search criteria i always get results as file not found
in excel file

wheni click on batch file where it exactly search ? when i open cmd prompt it default set as C:\>
but i want to search file in F:\> drive

how to provide path in this batch file.

i will appreciate any help on this

Again thanks for reply :)