Recursive file search using PowerShell

后端 未结 8 1493
情话喂你
情话喂你 2020-11-28 01:50

I am searching for a file in all the folders.

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

$Fil         


        
相关标签:
8条回答
  • 2020-11-28 02:49

    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.

    The 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 vice versa:

    dir -Path C:\FolderName -Filter FileName.* -Recurse | %{$_.FullName}
    
    0 讨论(0)
  • 2020-11-28 02:53

    When searching folders where you might get an error based on security (e.g. C:\Users), use the following command:

    Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force
    
    0 讨论(0)
提交回复
热议问题