You can specify multiple file masks within one DIR /B command. Based on your comment to Yair Nevet's answer, it seems you want the following extensions: .ovr
, .inc
, and .dat
. That can be done simply using:
dir /b /s *.ovr *.inc *.dat >i67.txt
If the files are on an NTFS volume that has short 8.3 names enabled, then you might get additional undesired file extensions if you have any file extensions longer than 4 characters that begin with your wanted extension. For example someName.data
would show up in your output because it most likely would have a short name of SOMENA~1.DAT
that matches your file mask.
You can prevent short name inclusion by piping the output to FINDSTR. The /L
option forces a literal search as opposed to regular expressions, the /I
option ignores case, and the /E
option matches only the end of each line. Multiple search terms are delimited by spaces.
dir /b /s *.ovr *.inc *.dat | findstr /lie ".ovr .inc .dat"
Regarding your following comment:
Here is what I am using now: dir /b | findstr [a-z].*ovr>i67.txt &&
dir /b | findstr [a-z].*inc>>i67.txt && dir /b | findstr
[a-z].*dat>>i67.txt What it does?? --- It copies all
names(remember,only name except files itself which are ending with
extension .ovr .dat and .cpi ) present in a directory and copy it to a
text file(here name is i67.txt)
That will not actually do what you want for several reasons.
Windows file names are not case sensitive. Windows would treat NAME.OVR and name.ovr the same, so you should as well. That requires the /I
option.
There is nothing in your search to anchor ovr to the extension. It will look for your pattern anywhere within the file name. And the dot is a meta character that represents any character - not a literal dot. The asterisk allows the dot to match any number of characters.
I can't be sure, but it looks like perhaps you only want to match files that begin with a letter. The following modification to my answer should do the trick:
dir /b /s *.ovr *.inc *.dat | findstr /ri "^[a-z].*\.ovr$ ^[a-z].*\.inc$ ^[a-z].*\.dat$"
The \R
option forces a regular expression match instead of a literal. It is the default behavior for the given search, but it is a good idea to be explicit with regard to regex vs literal search.
^
anchors the search to the beginning of the name
[a-z]
matches any letter (sort of). Remember it is not case sensitive because of the /I
option. Without the /I
option, it would not match upper case Z
. See Why does findstr not handle case properly (in some circumstances)? for an explanation.
.*
matches any number of characters, without restriction
\.
matches a dot literal, marking the beginning of your extension
Then comes your extension
$
anchors the match to the end of the name