小编use*_*287的帖子

Powershell - IO.Directory - 查找所有子目录中的文件类型

我在另一篇文章中遇到了这段代码,它几乎满足了我的需要,但不知道如何修改它来查找特定的文件类型,即 *.bak、.txt 等。我正在使用 Powershell 和 [System .IO.DirectoryInfo] 因为,就像其他人所说的那样,使用 Get-ChildItem 在网络上太慢了。我认为这只是 $fileEntries = [IO.Directory]::GetFiles("C:\", " .bak") 之类的东西,但它仍然返回每个目录中的每个文件。--PS/.NET新手

try
{
       $fileEntries = [IO.Directory]::GetFiles("C:\")
       [System.IO.DirectoryInfo]$directInf = New-Object IO.DirectoryInfo("C:\")
       $folders = $directInf.GetDirectories()
}
catch [Exception]
{
       $_.Exception.Message
       $folders = @()
 }

foreach($fileName in $fileEntries) 
{

      #[Console]::WriteLine($fileName); 

}

Remove-Variable -ErrorAction SilentlyContinue -Name fileEntries 

foreach($folder in $folders)
{
    recurse("C:\" + $folder + "\")
}
Run Code Online (Sandbox Code Playgroud)

.net powershell

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

.net ×1

powershell ×1