要递归搜索隐藏文件,我使用的是:
gci -Path C:\ -Filter part_of_filename* -Recurse -Force | where { $_.Attributes -match "Hidden"}
输出显示了许多与此完全相同的错误(取决于路径):
Get-ChildItem : Access to the path 'C:\Documents and Settings' is denied. At C:\Users\USERNAME\Documents\powershell\searchdisk.ps1:10 char:5 + gci <<<< -Path C:\ -Filter part_of_filename* -Recurse -Force | where { $_.Attributes -match "Hidden"} + CategoryInfo : PermissionDenied: (C:\Documents and Settings:String) [Get-ChildItem], UnauthorizedAccessException + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
我需要一个 PowerShell 命令,它可以递归搜索包括隐藏目录在内的任何目录,并向我显示所有文件,包括名为 part_of_filename* 的隐藏文件(对于本示例)
我以管理员身份使用 PowerShell ISE 运行了该命令。它不会在目录中搜索
C:\Windows\System32\LogFiles\WMI\RtBackup
最佳答案
你做得对。只需在提升的控制台中运行它并删除过滤器即可。如果你不关心权限错误,附加 -ErrorAction SilentlyContinue
:
Get-ChildItem -Path C:\ -Filter lush* -Recurse -Force `
-ErrorAction SilentlyContinue
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-arhs 25.09.2013 12:16 1208 lush.asx
lush.asx
具有 ReadOnly、Hidden 和 System 属性。
您可能还想通过管道传送到 |选择 Name, Length, Directory
以摆脱不幸的 Directory: C:\
行。如果您想要没有文件名的完整路径,还有一个 DirectoryName
。
关于powershell - 如何使用PowerShell递归搜索目录中的所有文件,包括隐藏目录中的隐藏文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425297/