Reputation: 19
The main idea of this post is that, given a path to folder or disk. Then powershell will search all file and folder inside this path and list all the extension file current stored in this path (docx, xlsx, jpg,...)
The final results will be stored in csv file.
Upvotes: 0
Views: 1562
Reputation: 1435
I've made a little fix in the svanzundert solution
$Folder = "C:\Temp\"
Get-ChildItem $Folder | Select Extension -Unique | Where-Object{$_.Extension -ne ""} | Export-Csv -Path C:\Temp\YourCSV.csv -NoTypeInformation
You just have to use -Unique parameter in the Select-Object
Upvotes: 1
Reputation: 1277
For sure there will be better ways, like use filter to get from childs files onlz but zou can do something like follows:
#will load directory content
$files = Get-ChildItem "C:\Users\fooo\Documents\"
#empty array for extensions preparation
$extensions = New-Object System.Collections.ArrayList($null)
#iterate over items= files and directories
for ($i=0; $i -lt $files.Count; $i++) {
#print all (once by one of course)
#Write-Host $files[$i].FullName
#print extension only
#Write-Host $files[$i].Extension
#store extensions by unique, if its a file
if( ($files[$i].GetType().Name -eq "FileInfo" ) -and !$extensions.Contains($files[$i].Extension) ){
$extensions.Add($files[$i].Extension)
}
}
Write-Host $extensions
my output:
.gitattributes .gitignore .mailmap .yml .cmd .fsx .sh .md .dependencies .lock .sln .DotSettings
Upvotes: 0
Reputation: 63
I think you want something like this, but could be I misunderstood your question.
$Folder = "C:\Temp\"
Get-ChildItem $Folder | Select Extension | Where-Object{$_.Extension -ne ""} | Export-Csv -Path C:\Temp\YourCSV.csv -NoTypeInformation
Upvotes: 1