A few words of thanks would be greatly appreciated.

Batch - To search (Search.bat)

How to search using command?

First the batch file needs to be called "search.bat" as you are typing Search.
The other thing is that the search.bat file should be in the same folder from where you are trying to run it. Other option would be the have the path where the search.bat resides added the environment variable "PATH"

One change to the code is needs as it seems that you are passing two parameters. One the director and the other the characters of the file

Save the code below Search.bat in your root c:\
  • Once saved,
  • Type: cmd
  • Then type: cd /d c:\
  • Then run search file,
    • example:

search "c:\windows" "sys"

REM search.bat 

set folder=%~1 
set str=%folder:~-1% 
if %str%==\ GOTO MoveOn 
set folder=%~1\ 

set files=*%~2* 

set searchFor="%folder%%files%" 
dir /a-d %searchFor%


Thanks to rizvisa1 for this tip on the forum.

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.


Published by . Latest update on by aakai1056.

This document, titled "Batch - To search (Search.bat)," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).