Saturday, April 3, 2010

Searching Files with Command Prompt

We all are familiar to searching files in our computer. (Just click on start->search->File and folders). It is all the GUI process for searching files.

Here something new - It is searching files with command. Now here question in your mind that we already have good GUI option to search files then why we consider command for it. The answer is very simple - it is not for normal users to search file but it is for developers. If you design such program where you need searching at that time you can use it.

Steps for setup -

1. Open Notepad.

2. Write this code (Do not change any sequence of this code)
@ECHO OFF
REM Find a file on this disk
IF !%1==! GOTO ERROR
ECHO Looking...
DIR \%1 /S /B > _TOTAL_
ECHO Total Finds:
FIND /C ":" _TOTAL_
IF ERRORLEVEL 1 GOTO NONE
PAUSE
MORE <>
:NONE
DEL _TOTAL_
GOTO END
:ERROR
ECHO Follow Search with the name of the file you want to find
:END

3. Save this file in C:\Windows\System32\Search.Bat

4. Set System Variable
-> Right click on My Computer
-> Go to Advanced->Environment Variables->System Variables
-> Click on New (Vari. Name - Search and Vari. Value - C:\Windows\System32\Search.Bat)

5. Open CMD and type search file_name

Note - It is also searching files with Wildcards

No comments:

Post a Comment