public ActionResult getTree(string path) { if (!System.IO.Directory.Exists(path)) { return(NotFound()); } var name = System.IO.Path.GetDirectoryName(path); var files = System.IO.Directory.GetFiles(path) .Select(f => new Models.File { Name = System.IO.Path.GetFileName(f), Url = f }).ToList(); var subDirectories = System.IO.Directory.GetDirectories(path) .Select(d => new SubDirectory { Name = System.IO.Path.GetFileName(d), Url = d + "\\" }) .ToList(); var directory = new Models.Directory { Name = name, Files = files, SubDirectories = subDirectories }; return(Ok(directory)); }
public ICollection <IDirectory> OpenFolders() { var dialog = new CommonOpenFileDialog { IsFolderPicker = true, Multiselect = true, ShowHiddenItems = false }; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { var collection = new Collection <IDirectory>(); //var dir = new Models.Directory(dialog.SelectedPath); //collection.Add(dir); foreach (var pathname in dialog.FileNames) { var dir = new Models.Directory(pathname); collection.Add(dir); } //collection.Add(new Models.Directory(dialog.)) return(collection); } return(null); }
public Directory AddDirectory(string path) { Models.Directory directory = new Models.Directory(path); Directories.Add(directory); AddWatcher(directory); Program.Settings.SaveSettings(); CheckAllFilesForImports(); return directory; }
public static Models.Directory GetDirectory(string dir, Enum.FileEventEnum fileEvent = Enum.FileEventEnum.None) { Models.Directory directory = new Models.Directory(); directory.DirName = dir; directory.Files = new List <Models.File>(); foreach (var file in System.IO.Directory.GetFiles(dir)) { directory.Files.Add(new Models.File() { Name = file.Substring(file.LastIndexOf("\\") + 1), Event = fileEvent, MD5 = FileHelper.CalculateMD5(file) }); } return(directory); }
public Models.Directory Read(string currentPath, string pathToBrowse) { //if (currentPath == "This PC") // return GetDirectory(new DirectoryInfo(pathToBrowse)); if (pathToBrowse == "backward") { var directoryInfo = new DirectoryInfo(currentPath); if (directoryInfo.Parent != null) { return(GetDirectory(directoryInfo.Parent)); } pathToBrowse = "This PC"; } if (pathToBrowse == "This PC") { var directory = new Models.Directory(); directory.Path = "This PC"; foreach (var item in DriveInfo.GetDrives()) { if (!item.IsReady) { continue; } var file = new Models.File(); if (item.VolumeLabel != "") { file.Name = item.VolumeLabel + " (" + item.Name.Substring(0, 2) + ")"; } else { file.Name = "Local Disk (" + item.Name.Substring(0, 2) + ")"; } file.Path = item.Name; directory.Directories.Add(file); } return(directory); } return(GetDirectory(new DirectoryInfo(pathToBrowse))); }
public static IList <Models.Directory> GetDirectories(string[] directories, Enum.FileEventEnum fileEvent = Enum.FileEventEnum.None) { List <Models.Directory> result = new List <Models.Directory>(); if (directories.Any()) { foreach (var dir in directories) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } Models.Directory directory = new Models.Directory(); directory.DirName = dir; directory.Files = new List <Models.File>(); foreach (var file in System.IO.Directory.GetFiles(dir)) { directory.Files.Add(new Models.File() { Name = Path.GetFileName(file), Event = fileEvent, MD5 = FileHelper.CalculateMD5(file) }); } result.Add(directory); var subDirectories = System.IO.Directory.GetDirectories(dir); if (subDirectories.Any()) { subDirectories = subDirectories.Select(c => c += "\\").ToArray(); result.AddRange(GetDirectories(subDirectories, fileEvent)); } } } return(result); }