Searching in cmd

Solved/Closed
persiansushiant - Jan 31, 2010 at 01:17 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jan 31, 2010 at 04:14 PM
Hello,
i want to write a batch file that allows me to search a name in cmd for example if i write this command in cmd search c:\new folder s
everyfile that has s in the name of it should be listed like see saw or anything else
Related:

6 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jan 31, 2010 at 04:14 PM
if the 4 points i said were correct. then 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 the characters of the file

Save the code below Search.bat in your root c:\

once save, type cmd
then type cd /d c:\
then run search file
example
search "c:\windows" "sys"


REM search.bat

@ECHO OFF
cls
set folder=%~1
set str=%folder:~-1%
if %str%==\ GOTO MoveOn
set folder=%~1\

:MoveOn
set files=*%~2*

set searchFor="%folder%%files%"
dir /a-d %searchFor%
1
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jan 31, 2010 at 01:24 PM
use dir command. To see what you can do with dir, use dir /? command

for your example
dir /a-d "C:\new folder\*s*"
0
persiansushiant
Jan 31, 2010 at 01:29 PM
no actually i want to make a command not using dir i want to write a batch file
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jan 31, 2010 at 02:06 PM
Not entirely clear about what you are want to accomplish. If just you want to run the command as a batch, you can simply type the same into the batch program and run it.

in case you want to hard code the dir
dir /a-d "c:\new folder\*s*"

In case you want to supply it as a parameter. In this case enclose the c:\new folder\*s* in the ". Say batch file is test.bat, then run it as test "c:\new folder\*s*"
dir /a-d %1


If you are trying to capture the result, you may want to pipe it to some file, like
dir /a-d "C:\new folder\*s*" > mysearch.txt
0
persiansushiant
Jan 31, 2010 at 02:34 PM
u didnt understand what i say i want to write in cmd "search c:\windows s"
i want to add command search to cmd and define it anything which has s in name.
0

Didn't find the answer you are looking for?

Ask a question
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jan 31, 2010 at 03:00 PM
Well correct me where I am falling off.
1. you are using vista
2. when you say "cmd" you are talking about the command "cmd" that open a dos sort windows.
3. you would be typing in cmd and open the dos window
4. there you would be typing in command "search c:\windows s"

If that all is correct, then the command i gave you would work. Only thing that needs to be ensured is that the location of the path is where the cmd windows open or is available in the PATH
0
persiansushiant
Jan 31, 2010 at 03:26 PM
i want to write search in cmd i did what u said but when i write search it doesnt understand and there is error
0