I currently have this code which returns the total number of files but I don't want to count multiple files in this number count?
Lets say I have this:
01Red.txt
01Blue.txt
02Red.txt
05Red.txt
05Green.txt
Get-ChildItem -File *.txt -Path "C:\Users\Test\Desktop\TestDirectory" | Measure-Object | %{$_.Count}
I want to return a total count of 3 based on 01,02,05 but with my code I get 5.
How can I get it to return 3 and ignore everything past the first 2 characters in the string?
I might suggest Group-Object
:
Get-ChildItem *.txt | Group-Object { $_.Name.Substring(0,2) }
Add | Measure-Object
to count the number of groupings (this would be 3 in your example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With