尝试这个:
function Get-ExtensionCount {
param(
$Root = "C:\Root\",
$FileType = @(".sln", ".designer.vb"),
$Outfile = "C:\Root\rootext.txt"
)
$output = @()
Foreach ($type in $FileType) {
$files = Get-ChildItem $Root -Filter *$type -Recurse | ? { !$_.PSIsContainer }
$output += "$type ---> $($files.Count) files"
foreach ($file in $files) {
$output += $file.FullName
}
}
$output | Set-Content $Outfile
}
我把它变成了一个函数,你的值作为默认参数值。通过使用调用它
Get-ExtensionCount #for default values
或者
Get-ExtensionCount -Root "d:\test" -FileType ".txt", ".bmp" -Outfile "D:\output.txt"
输出保存到文件 ex:
.txt ---> 3 files
D:\Test\as.txt
D:\Test\ddddd.txt
D:\Test\sss.txt
.bmp ---> 2 files
D:\Test\dsadsa.bmp
D:\Test\New Bitmap Image.bmp
要在开始时获取所有文件计数,请尝试:
function Get-ExtensionCount {
param(
$Root = "C:\Root\",
$FileType = @(".sln", ".designer.vb"),
$Outfile = "C:\Root\rootext.txt"
)
#Filecount per type
$header = @()
#All the filepaths
$filelist = @()
Foreach ($type in $FileType) {
$files = Get-ChildItem $Root -Filter *$type -Recurse | ? { !$_.PSIsContainer }
$header += "$type ---> $($files.Count) files"
foreach ($file in $files) {
$filelist += $file.FullName
}
}
#Collect to single output
$output = @($header, $filelist)
$output | Set-Content $Outfile
}