[Help]Finding or Searching File in your own Computer.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
[CMD]Newbie
Posts: 1
Joined: 10 Mar 2010 12:05

[Help]Finding or Searching File in your own Computer.

#1 Post by [CMD]Newbie » 10 Mar 2010 12:12

Any Pro' know how to make a code in batch file to "find or search a file in your computer?

I give up searching in google but still can't find any solution with it.

Tnx advance.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: [Help]Finding or Searching File in your own Computer.

#2 Post by aGerman » 10 Mar 2010 12:38

Maybe something like that:

Code: Select all

@echo off &setlocal

set filename=example.txt

pushd c:\
for /f "delims=" %%a in ('dir /a-d /b /s "%filename%"') do set "fullname=%%a" &set "filepath=%%~dpa"
popd

echo %fullname%
echo %filepath%
pause


It's looking for "example.txt" on drive C:. Note that it needs a lot of time.

SenHu
Posts: 19
Joined: 19 Mar 2009 14:57

Re: [Help]Finding or Searching File in your own Computer.

#3 Post by SenHu » 16 Mar 2010 10:30

I doubt if I am a pro, but here is a solution anyway using biterscripting.

To search for a file

lf -r -n -g "*example*" "C:/somefolder"

will show all files matching the pattern "example*" under the folder tree at "C:/somefolder".

To search for a string within the contents of files

script SS_FindStr.txt str("today") files("*.txt") dir("C:/somefolder")

will display all files matching the pattern "*.txt" containing the search string "today" under the folder tree at "C:/somefolder". It will show this output.


File: C:/somefolder/savedemails/986AC98DF09.txt
Line 34: Today is a good day to start the new project.
File: C:/somefolder/dailyreport.txt
Line 7: Daily report for today: March 10, 2010
.
.
.

If you want to search for regular expressions, use the script SS_FindRE.txt instead.

I use these to search the contents of my emails. You can find some more useful stuff at http://www.biterscripting.com .

Post Reply