Last active
April 4, 2018 09:12
-
-
Save asquigglytwist/02f9c9acec92b4bd03e51c764cdf2952 to your computer and use it in GitHub Desktop.
A few helper functions for assisting with operations on 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
public static List<string> GetFileNamesWithoutExtensionAsList(string dir, string pattern) | |
{ | |
if (Directory.Exists(dir)) | |
{ | |
return new DirectoryInfo(dir).GetFiles(pattern, SearchOption.TopDirectoryOnly) | |
.Select(file => Path.GetFileNameWithoutExtension(file.Name)).ToList(); | |
} | |
return new List<string>(); | |
} | |
public static IEnumerable<string> GetFileNamesWithoutExtensionAsIEnumerable(string dir, string pattern) | |
{ | |
if (Directory.Exists(dir)) | |
{ | |
return new DirectoryInfo(dir).GetFiles(pattern, SearchOption.TopDirectoryOnly) | |
.Select(file => Path.GetFileNameWithoutExtension(file.Name)); | |
} | |
return new List<string>(); | |
} | |
public static void CreateDirectory(string dirPath) | |
{ | |
if (!Directory.Exists(dirPath)) | |
{ | |
Directory.CreateDirectory(dirPath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment