0

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.

2
  • 2
    What have you tried, and how has what you've tried failed? Ideally, you should provide a minimal reproducible example of what you've tried, and include specific information on how it failed, with error messages and/or erroneous output. Stack Overflow is not a code-writing service; the best questions are those which provide useful information so that those who answer can guide you to devising your own correct answer. See How to Ask a Good Question. Commented Feb 28, 2019 at 14:59
  • Hi, welcome Stackoverflow, we are willing to help you, but as Jeff mentioned, don't rely we will make your homework, that's not how SO works :) Commented Feb 28, 2019 at 15:11

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Oh thanks. Now it doesn't repeat same extension anymore!
1

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

2 Comments

Thanks! That's exactly what I want! But it still have a small problem is that if I have 2 pdf file, it will list 2 extension pdf and pdf in CSV file?
There should be something like Get-Unique @ABCD check docs
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.