Recursive file search using PowerShell

I am searching for a file in all the folders.

Copyforbuild.bat is available in many places, and I would like to search recursively.

$File = "V:Myfolder***.CopyForbuild.bat"

How can I do it in PowerShell?


使用具有-Recurse开关的Get-ChildItem cmdlet:

Get-ChildItem -Path V:Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force

I know the question is old, but I could not make a comment to Shay Levy's answer.

When searching folders where you might get an error based on security (eg C:Users ) use the following command:

Get-ChildItem -Path V:Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force

I use this to find files and then have PowerShell display the entire path of the results:

dir -Path C:FolderName -Filter FileName.fileExtension -Recurse | %{$_.FullName}

You can always use the wildcard * in the FolderName and/or FileName.fileExtension. For example:

dir -Path C:Folder* -Filter File*.file* -Recurse | %{$_.FullName}

The above example will search any folder in the C: drive beginning with the word Folder . So if you have a Folder named FolderFoo and FolderBar PowerShell will show results from both of those folders.

Same goes for the file name and file extension. If you want to search for a file with a certain extension but don't know the name of the file you can use:

dir -Path C:FolderName -Filter *.fileExtension -Recurse | %{$_.FullName}

Or vise versa:

dir -Path C:FolderName -Filter FileName.* -Recurse | %{$_.FullName}
链接地址: http://www.djcxy.com/p/4952.html

上一篇: 如何用PowerShell替换文件中的每个字符串?

下一篇: 使用PowerShell进行递归文件搜索