public static void GetFilesFromDirectory(FileType type, ObservableCollection<CodeFile> collection, string directoryPath) { if (Directory.Exists(directoryPath)) { string[] extensions = null; switch (type) { case FileType.All: extensions = new string[] { ".cs", ".vb" }; break; case FileType.CS: extensions = new string[] { ".cs" }; break; case FileType.VB: extensions = new string[] { ".vb" }; break; } string[] files = Directory.GetFiles(directoryPath); foreach (string file in files) { if (!extensions.Contains<string>(Path.GetExtension(file))) continue; CodeFile cFile = new CodeFile(); PopulateCodeFile(cFile, file); collection.Add(cFile); } } }
static void PopulateCodeFile(CodeFile file, string filePath) { file.Name = Path.GetFileName(filePath); file.Path = filePath; file.Type = Path.GetExtension(filePath); file.Attributies.Size = (int)new FileInfo(filePath).Length; file.Attributies.TimeCreation = File.GetCreationTime(filePath); file.Attributies.TimeModification = File.GetLastWriteTime(filePath); }