Files can be found using DIR, FOR, FINDSTR, FORFILES, and WHERE.
Examples:
dir /b /s *base*.doc*
- Outputs all files in the current folder and its sub-folders such that the file name before the extension contains the word
base and whose extension starts with doc, which includes doc and docx. The files are output with full paths, one file per line.
dir /b /s *.txt | findstr /i pers.*doc
- Combines the result of outputting files including their complete paths with the
findstr filtering command supporting limited regular expressions, yielding a versatile and powerful combination for finding files by names and the names of their directories.
for /r %i in (*) do @if %~zi geq 1000000 echo %~zi %i
- For each file in the current folder and its sub-folders that has the size greater than or equal to 1,000,000 bytes, outputs the file size in bytes and the full path of the file. For the syntax in
%~zi, see percent tilde.
forfiles /s /d 06/10/2015 /c "cmd /c echo @fdate @path"
- For each file in the current folder and its sub-folders modified on 10 June 2015 or later, outputs the file modification date and full file path. The date format after
/d is locale specific. Thus, allows to find most recently modified files.
(for /r %i in (*) do @echo %~ti :: %i) | findstr 2015.*::
- Searching the current folder recursively, outputs files whose last modification date is in year 2015. Places the modification date and time, followed by a double colon, before the file name. Works as long as the used version of Windows and locale displays dates in a format that contains four-digit years. The double colon is used to make sure the
findstr command is matching the date and not the file name.
for /r %i in (*) do @echo %~ti | findstr 2015 >NUL && echo %i
- As above, outputs files changed in 2015. Unlike the above, only outputs the files, not the modification dates.
findstr /i /s /m cat.*mat *.txt
- Finds files by their content. Performs a full text search for regular expression cat.*mat in files with names ending in
.txt, and outputs the files names. The /m switch ensures only the file names are output.
where *.bat
- Outputs all .bat files in the current directory and in the directories that are in
PATH.