我想要一个命令,使用命令行在 Windows 中搜索目录和所有子目录中的文件。我查看了所有可用的命令,但找不到任何合适的命令来执行此操作。
答案1
在提示符(命令行)下输入:
dir /S /P "Path\FileName"
如果要将结果保存在文本文件中:
dir /S "Path\FileName" > "Path\ResultFilename"
答案2
使用/b
开关dir
打印完整路径可能会有所帮助。比如说,C:\ > dir /b /s *file*.*
find
不过,您可以使用或过滤结果for
,并使用将输出重定向到文件>filename
答案3
dir
原本不是用来搜索文件的,而是用来列出目录的,但现在有了where
可以用于搜索多种文件类型的
where /R c:\Users *.dll *.exe *.jpg
请检查完整语法和答案 如何在 cmd 中进行简单的文件搜索
WHERE [/R dir] [/Q] [/F] [/T] pattern...
Description:
Displays the location of files that match the search pattern.
By default, the search is done along the current directory and
in the paths specified by the PATH environment variable.
Parameter List:
/R Recursively searches and displays the files that match the
given pattern starting from the specified directory.
/Q Returns only the exit code, without displaying the list
of matched files. (Quiet mode)
/F Displays the matched filename in double quotes.
/T Displays the file size, last modified date and time for all
matched files.
pattern Specifies the search pattern for the files to match.
Wildcards * and ? can be used in the pattern. The
"$env:pattern" and "path:pattern" formats can also be
specified, where "env" is an environment variable and
the search is done in the specified paths of the "env"
environment variable. These formats should not be used
with /R. The search is also done by appending the
extensions of the PATHEXT variable to the pattern.
/? Displays this help message.
NOTE: The tool returns an error level of 0 if the search is
successful, of 1 if the search is unsuccessful and
of 2 for failures or errors.
Examples:
WHERE /?
WHERE myfilename1 myfile????.*
WHERE $windir:*.*
WHERE /R c:\windows *.exe *.dll *.bat
WHERE /Q ??.???
WHERE "c:\windows;c:\windows\system32:*.dll"
WHERE /F /T *.dll