Batch file to find file in folder & subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Maheshp
Posts: 6
Joined: 25 Jul 2011 20:22

Batch file to find file in folder & subfolders

#1 Post by Maheshp » 27 Jul 2011 13:01

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.

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: Batch file to find file in folder & subfolders

#2 Post by renzlo » 28 Jul 2011 03:23

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

Maheshp
Posts: 6
Joined: 25 Jul 2011 20:22

Re: Batch file to find file in folder & subfolders

#3 Post by Maheshp » 31 Jul 2011 11:30

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

Post Reply