MS-DOS – Searching a file

April 2018


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
every files that has s in the name of it should be listed like see saw or anything else.


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


Thanks to rizvisa1 for this tip on the forum.
Published by aakai1056. Latest update on January 31, 2010 at 03:35 PM by aakai1056.
This document, titled "MS-DOS – Searching a file," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
DOS: create filename based on date?
Attrib Command Syntax