Last active
August 3, 2022 20:16
-
-
Save naturallucky/2d3baf49b2a268a1b73ddf82c780b4ec to your computer and use it in GitHub Desktop.
PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://edutainment-fun.com/hidemaru/microsoft/%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%94%E3%81%A8%E3%81%AE%E8%A1%8C%E6%95%B0%E3%82%92%E3%82%AB%E3%82%A6%E3%83%B3%E3%83%88%E3%81%99%E3%82%8B%E3%80%90powershell%E3%80%91_3563.html | |
Function Get-TotalFileNumOfEachDir() { | |
if ($args.Length -ne 2) { | |
$Host.UI.WriteErrorLine("Usage: Get-TotalFileNumOfEachDir <path> <filter:*.cs>") | |
return | |
} | |
$pathto = $args[0] | |
$filters = $args[1].Split(",") | |
if (!(Test-Path -PathType Container $pathto)) { | |
$Host.UI.WriteErrorLine("Cannot access $pathto : No such directory") | |
return | |
} | |
echo (Resolve-Path $pathto).Path | |
foreach($filter in $filters){ | |
$outputsArray = @() | |
$dirs = Get-ChildItem $pathto | Where-Object PSisContainer | |
$dirs | % { | |
$PATH=$_; | |
if ((Get-ChildItem $_.FullName).Length -ne 0) { | |
$measure = Get-ChildItem -Force -Recurse $_.FullName -Include $filter | Get-Content | Measure-Object -Line -Word -Character | |
$outputsArray += [PSCustomObject]@{ PATH=$PATH; Line=$measure.Lines; Word=$measure.Words; Char=$measure.Characters } | |
} else { | |
$outputsArray += [PSCustomObject]@{ PATH=$PATH; Line=0; Word=0; Char=0 } | |
} | |
} | |
#$header =(Resolve-Path $pathto).Path + " $filter" | |
echo $filter #$header | |
$outputsArray | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment