Introduction: Helpful Batch File Search

Picture of Helpful Batch File Search

Hello.
This is my first instructable. so if I made a mistake please go easy on me.

I had made a simple batch file searcher, to help my self finding the files I need in my HDD jungle.
This batch is so much faster than standard windows search(windows button +f).

Pros:
- Very fast
- easy to make.
- Portable (infact you can memorize all the commands)
- using it makes you look very cool. :D

Cons:
- Limited to file name search only.
- must update data base regularly.
- update might took forever :)

I've searched instructable for similar batch file but found none.
That encourage me to make one.

Step 1: Getting Prepared

Picture of Getting Prepared

1. run cmd on Start->run, type in cmd, press enter.
2. create a new folder. (md anything)
3. add the new folder to your system path variable
control panel->system properties->advanced->environment variable->select path->edit->ok
4. check it on the command window by typing "path" followed by enter button.
5. explore to your new folder.
6. create two new text document.
7. rename one of them into update.
8. rename the other one into search.

Step 2: First Batch File

Picture of First Batch File

this is the content of the update.txt file
just copy and paste it into the update.txt

::start
@title UPDATE
@del k:\finder\allfiles.log
@dir c:\ d:\ e:\ f:\ G:\ h:\ I:\ J:\ K:\ /s /a /b >> K:\finder\Allfiles.log
::end

please edit the folder "K:\finder" into the folder name you just made.

save it

note :
you can add or remove the drive letter to suit your system.
the command above will be indexing file name from drive letter C to K.

Step 3: Second Batch File

Picture of Second Batch File

This is the content of the second file
search .txt
just copy paste it.
::start
@echo off
Title Search
echo use \.extension $ for seeking extenson of file ie:*.mp3
color 0a
findstr /I /L /A:FC "%1 %2 %3" k:\finder\allfiles.log |more
::end

please edit the folder "K:\finder" into the folder name you just made.
save it.

Step 4: Rename the Text Document

Picture of Rename the Text Document

go to your command prompt
type
ren *.txt *.bat
press enter
you should get 2 new batch file now instead of text document.

Step 5: Creating the Logs

Picture of Creating the Logs

now run the update.bat
and wait for..........quite some time.
relax it might took 5 to 15 minutes to finish.


after it got finished it will create new file called
allfiles.log
a huge one :)

Step 6: Action

Picture of Action

then you can run the search.bat file.
sample of usage

search update
search \.doc (for searching file extension)

more control:
press enter to get one line scrolling.
press space bar to get page scrolling.
press ctrl+c to quit searching.

since it already on your system path you can ran both search and update from any folder,
or even from the run command.

actually if you are an advanced user you can skip few step of this instructible.
hope it will became handy for you as it did for me.
thank you for reading.

Comments

JohnS52 (author)2015-02-05

I want to make Batch file able to make and write to .txt files, then everytime I start it it searches for .txt files in the folder it is. How?

Utest222333 (author)2014-12-24

Like

ckirk3 (author)2013-05-21

This is really complicated. Maybe you could post a downloadable version of it...

cmdmaster (author)2010-11-16

No wonder any of these work! They contain wrong Command Sets!!!

FumaKilla (author)cmdmaster2010-11-17

elaborate please.

TheBatchies (author)2010-01-24

I'm terribly sorry, but the grammar and spelling in this instructable was just terrible. I honestly couldn't understand a thing. Better luck next time.

FumaKilla (author)TheBatchies2010-01-24

 thank you, English is my second language. I think i did the best :(

TheBatchies (author)FumaKilla2010-01-28

Oh, sorry! I didn't know. I didn't mean it like that, I though you were doing it on purpose! I thought you were purposely trying to make it like that, but I understand now. Oh, I'm really sorry! Please understand!

FumaKilla (author)TheBatchies2010-06-01

:) no worries...
You're not the only one and I did get that a lot...  so I get used to it... XD.  
cheers.

J-Manoo7 (author)2009-09-28

i know this is an older instructable but i was wondering if i could still get any help. I am trying to perform a search on my computer but instead of searching in a list of the file names, i want to find files on my computer that match the files names i give it, preferably line by line in a text file, example: file1.txt file5.exe lots_of_junk.html i can give this in a text file and have one file on every line of the text. next (which is where my problem is) is i need the computer to find the files that have the same name of the files given and copy, delete, or move them. the end result should be able to find the file anywhere on the system even if the file is hidden. If i need to elaborate on anything let me know, thx for the help

FumaKilla (author)J-Manoo72009-09-30

i don't get what you're asking clearly so this is my guesses : 1. if you want to search for files in a given file name list. that is not possible to do in batch file. you'll need to write a program. phyton is free and easy to learn. 2. however you can create a list of specific file you want to look for by doing : (you'll have to do step 1-5 of this instructable first) search file1.txt >> file1.log search file5.exe >> file5.log search lots_of_junk.html >> lots_of_junk.log the new log file that created will only contain the result that matches the filename you've given. 3. to be able to do actions such as move copy delete of the search result you'll have to write a program for it. or simple yet just use that (windows key + f, if you had windows os) 4. the dir parameter i used on this instructable is able to find hidden and system files. hope that help :)

J-Manoo7 (author)FumaKilla2009-10-01

#1 it can be in a given list, but it can also be in the program itself, i was trying to do an 'if exist' but the options of where it searches are limited # 2 seems like it will work, i will create this and try it on my computer and see how it works #s 3 and 4, well i would do that but, to elaborate on the purpose of the program i wish to write, this will be stealth-run on a friend's computer who copied the (dangerous) contents of my flash drive. he made copies to multiple computers and removable memory so im looking for a way to run an automated search that can find the location of the files and put them in a log (like #2 that you suggested) so i can delete them manually. i could have the program auto delete but if another file on the system is named the same as one of my files then it would also be deleted. and if he has renamed any of my files i want to know where the rest of them are. they will be hidden from the search is he renames them, but he copied my entire flash drive so he would be renaming for a long time and i know he won't rename them all because some of them are dependent upon other files. i already know how to get it on his computer and to run in stealth. also, does your program find and log hidden files? and can it find folders? thx for the help, again if you need any clarification just say so

FumaKilla (author)J-Manoo72009-10-09

if the purpose you asking this is for retrieving "stolen" files... i guess you can do this by putting up the batch on your removable storage and use the autorun.inf to automatically run the batch once done... you have to go away from your friend "analyzing" the result log. once done, you will know where the targeted files are. you can retreive it manually or using software aid.  but once renamed it's hard to find file like that. 
the dir command in the batch file are capable to find hidden files and folders. since it searches the string it will return any matched string whether that is a folder or a file.
sorry for the long reply.

J-Manoo7 (author)FumaKilla2009-10-10

no problem, i will probably retrieve it with software aid, and im only going to scan and log his C:\ drive, he always puts hidden stuff there because the large WINDOWS and system directories would make it hard to find manually, he has to use the .bat file extension so i will also search for that, he has although re-named every file that he copied so i will have to review alot of the results manually, which will take a very long time, but the names should stand out and seem out of place, thx for the help

Psychic Master (author)2009-07-11

nevr mind i found it it was named differently

Psychic Master (author)2009-07-11

im using vista and i cannot find the system properties in my control pannel...

hg341 (author)2009-06-04

very nice you could have it set to run every night at 3 am

hg341 (author)hg3412009-06-04

hey i want to do this for my flash drive how do i get the dir command it know is drive letter

FumaKilla (author)hg3412009-06-04

just add the drive letter of your flash drive where it used to be mounted. To the update.bat. or remove all drive letter but your flash drive, to make it a flash drive indexer. be sure to plug the flash drive before you run update. or you end up getting "The system cannot find the path specified." as result.

hg341 (author)FumaKilla2009-06-05

well im runing this for my flash dirve on my flash drive so i can use it on more then one pc i came up with this to slove my promble
my updater
"
echo drive letter:
@set /p d=
@title UPDATE
@del k:\finder\allfiles.log
dir k:\ /s /a /b >> D:\finder\Allfiles.log
"
the finder
"
@set /p d=
echo drive letter:
:start
@echo off
Title Search
color 0a
set /p str=
findstr /I /L /A:FC %str% %d%:\finder\allfiles.log
goto start
"

oh yea do you know how to use if commands?

FumaKilla (author)hg3412009-06-05

you are going to make an index of your flash drive, so you can search every where you go? (please correct me if I'm wrong)

::update start
@title UPDATE
@del allfiles.log
@dir /s /a /b >> Allfiles.log
::update end

::search start
@echo off
Title Search
echo use \.extension $ for seeking extenson of file ie:*.mp3
color 0a
findstr /I /L /A:FC "%1 %2 %3" allfiles.log |more
::search end

use the batch above to make it portable. just put it on the root directory (not in a folder) of your flash drive. but you can only ran it from the root directory of your flash drive.
IMHO : your modification is nice, but it need more key stroke to get to result. that would be tiring if you do it repetitively.
I must warn you, since flash drive reading and writing speed is inferior to a hard drive it will took long initial loading process but it get faster once it got cached.

and about the IF command you can read it here :
http://home7.inet.tele.dk/batfiles/batfiles.htm

hg341 (author)FumaKilla2009-06-05

it only takes a few secs to do my 4 gb so as for the speed thing im fine
i want to ask you something
what is the "|more" for

and i saw you have no drive letter dose that just make do the drive that it is running on?

thanks for the if

FumaKilla (author)hg3412009-06-05
More is used for : Displays output one screen at a time.
usage:
MORE [/E [/C] [/P] [/S] [/Tn] [+n]] < [drive:][path]filenamecommand-name | MORE [/E [/C] [/P] [/S] [/Tn] [+n]]MORE /E [/C] [/P] [/S] [/Tn] [+n] [files]
yep, if you didn't assign specific place for a command(ie: k:\finder) it will start in the default directory (the current directory/folder).
it's my pleasure :)
hg341 (author)FumaKilla2009-06-06

oh wow this is so cool i have learned more off the 'ible then any other for batch files (so thanks alot!)

FumaKilla (author)hg3412009-06-04

thank you.

lemonie (author)2009-06-02

Do I understand that you're creating an index of your entire system, and then searching that?
How quick will it do this, e.g. if I want to find a document I know I've got somewhere in 150GB across 2 drives?

L

FumaKilla (author)lemonie2009-06-02

Yes, in short that what it does. the update.bat only need to be run once after every major file change. in reality i ran update.bat once a week, or less. (it took 5mins on my 200 GB drive). the search.bat took less than 1mins to start giving out result (actually the speed is much more likely to depend on your reading speed). other than that, it is very fast.

lemonie (author)FumaKilla2009-06-02

Yes, I seem to think there might be a use to the index. If you imported into Excel delimiting with "\" you've got a spreadsheet index which you can search & filter also. If I get around to trying it I'll let you know. L

FumaKilla (author)lemonie2009-06-04

that would be one gigantic xls file. :) btw about that "L" signature, did you happen to be a fan of death note? I'm Kira :D

lemonie (author)FumaKilla2009-06-04

death note? (no just a habit) I am inclined to try this in Excel, the CTRL-F search is very fast, and you can add an auto filter. If you can import as hyperlinks it'll be useful. L

FumaKilla (author)lemonie2009-06-05

ah finally I understand where you are going :D I'm also created a program using phyton as an advanced version of findstr, so it can became file name specific. but that isn't batch file :)

lemonie (author)FumaKilla2009-06-05

It does work. How long does it take to pull up all your jpgs with a normal search? Loaded into Excel the autofilter does it real easy (I've got 6626). I might make an Instructable if I figure out a nice way of importing the file.

L

FumaKilla (author)lemonie2009-06-05

if you haven't know it yet, actually you can make a sub index of the huge index : search \.jpeg \.jpg >> image.log the new file image.log will contain all jpg and jpeg you have. that way you can import specific index to the excel. hope that help.

lemonie (author)FumaKilla2009-06-06

But I can filter for any file type with Excel. |Still playing with it...

L

PKM (author)2009-06-03
One thing that might help with this project- if you run
schtasks /create /sc WEEKLY /d SAT /tn Search-Indexer /tr K:\finder\update.bat /st 21:00:00 /ru username /rp password
from the command line, it will create a scheduled task that runs the update script every saturday at 9pm. You'll have to replace K:\finder\update.bat with the path of the update script, and "username" and "password" in the command above with your own username and password, and that will create a scheduled task. You can also of course change SAT to another day, replace the time, make it daily etc.- this page explains more about the schtasks command. You can then modify and delete the task using Scheduled Tasks in control panel.
FumaKilla (author)PKM2009-06-04

Thank you. I did add "update.bat" to scheduled task, but not by using schtasks.

About This Instructable

15,311views

8favorites

License:

Bio: just another ordinary guy who like experiments
More by FumaKilla:Helpful Batch File Search
Add instructable to: