Last active
November 18, 2015 22:59
-
-
Save hanssens/9a43f61e63a3782a72e8 to your computer and use it in GitHub Desktop.
ScriptCS script that extracts all unique file extensions from a directory
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
using System.IO; | |
// extracts all file extensions from a specified directory | |
// and spits them out in the console | |
var path = Directory.GetCurrentDirectory(); | |
var root_path = new DirectoryInfo(path); | |
// this fetches all file info, extracts the extension, | |
// filters the unique ones and sorts them, before outputting it | |
// alternatively, you may use 'SearchOption.AllDirectories' for recursive search | |
var extensions = root_path.GetFiles("*.*", SearchOption.TopDirectoryOnly) | |
.Select(f => f.Extension) | |
.Distinct() | |
.OrderBy(f => f) | |
.ToList(); | |
Console.WriteLine(string.Join(Environment.NewLine, extensions)); | |
/* | |
# sample output | |
$ scriptcs foo.csx | |
.csx | |
.DS_Store | |
.txt | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment