I’m trying to write a one-liner in Powershell that lists all filetypes in a folder (and its sub-folders).
I’ve got this so far:
Get-ChildItem D:\Audio -Recursive | Select-Object PSParentPath, Extension | Export-Csv D:\Test.csv
However, I’d like to do better and display, for each folder, every found extension only once.
For example, let’s say I have ten mp3 files and 1 jpg file in D:\Audio\foo and 5 flac files and 1 txt file in D:\Audio\bar. I’d like the output to be :
- foo .mp3
- foo .jpeg
- bar .flac
- bar .txt
I guess I should use Get-Unique but how do I specify it on the Extension property and NOT on the Path property?
Just add -Unique to Select-Object:
(Also, DirectoryName might be better than PSParentPath here)