private void loadComposites(string path, IComponent root) { try { string[] files = Directory.GetFiles(path, "."); } catch { Console.WriteLine("Folder doesn't exist!"); return; } try { string[] folders = Directory.GetDirectories(path); foreach (string folderPath in folders) { this.id++; dir folder = null; folder = new dir { path = folderPath, id = this.id, name = new DirectoryInfo(folderPath).Name, folder = true, root = root, link = System.IO.File.GetAttributes(folderPath).HasFlag(FileAttributes.ReparsePoint) }; root.AddComponent(folder); loadComposites(folderPath, folder); } loadLeafs(path, root); root.CalculateSize(); } catch { Console.WriteLine("Error"); } }
private void copyFolder(string what, string where, IComponent root) { DirectoryInfo dir = new DirectoryInfo(what); DirectoryInfo[] dirs = dir.GetDirectories(); DirectoryInfo _dir = Directory.CreateDirectory(where); this.id++; dir directory = null; directory = new dir { path = _dir.FullName, id = this.id, name = _dir.Name, folder = true, root = root, link = System.IO.File.GetAttributes(_dir.FullName).HasFlag(FileAttributes.ReparsePoint) }; root.AddComponent(directory); foreach (DirectoryInfo subdir in dirs) { string tempPath = Path.Combine(where, subdir.Name); copyFolder(subdir.FullName, tempPath, directory); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { this.id++; string temppath = Path.Combine(where, file.Name); FileInfo temp = file.CopyTo(temppath, false); file dat = new file { path = temp.FullName, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = directory, permitWriting = !temp.IsReadOnly, link = System.IO.File.GetAttributes(temp.FullName).HasFlag(FileAttributes.ReparsePoint) }; directory.AddComponent(dat); } }
private void CopyDirectory(string what, string where, IComponent root) { DirectoryInfo dir = new DirectoryInfo(what); DirectoryInfo[] dirs = dir.GetDirectories(); DirectoryInfo _dir = Directory.CreateDirectory(where); this.id++; dir directory = null; if (DS_Type == "NTFS") { directory = new dir { path = _dir.FullName, id = this.id, name = _dir.Name, folder = true, root = root, link = System.IO.File.GetAttributes(_dir.FullName).HasFlag(FileAttributes.ReparsePoint) }; } else if (DS_Type == "exFAT") { if (!System.IO.File.GetAttributes(_dir.FullName).HasFlag(FileAttributes.ReparsePoint)) directory = new dir { path = _dir.FullName, id = this.id, name = new DirectoryInfo(_dir.FullName).Name, folder = true, root = root, link = false }; } root.AddComponent(directory); foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(where, subdir.Name); CopyDirectory(subdir.FullName, temppath, directory); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { this.id++; string temppath = Path.Combine(where, file.Name); FileInfo temp = file.CopyTo(temppath, false); file dat = new file { path = temp.FullName, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = directory, permitWriting = !temp.IsReadOnly, link = System.IO.File.GetAttributes(temp.FullName).HasFlag(FileAttributes.ReparsePoint) }; directory.AddComponent(dat); } }
public bool CreateComponent(int where, string name, bool isDirectory) { IComponent _where = main.FindComponent(where); if (!_where.folder) { Console.WriteLine("Destination has to be a directory!"); return(false); } else { this.id++; IComponent root = null; if (isDirectory) { root = new dir { path = _where.path + '\\' + name, id = this.id, name = name, folder = true, root = _where, link = false }; } else { root = new file { path = _where.path + '\\' + name, id = this.id, name = name, folder = false, root = _where, link = false, permitWriting = true }; } if (root == null) { return(false); } else { _where.AddComponent(root); _where.CalculateSize(); } } return(true); }
public bool CreateComponent(int where, string name, bool isDirectory) { IComponent _where = main.FindComponent(where); if (!_where.folder) { Console.WriteLine("Destination has to be a directory!"); return false; } else { this.id++; IComponent root = null; if (isDirectory) { root = new dir { path = _where.path + '\\' + name, id = this.id, name = name, folder = true, root = _where, link = false }; } else { root = new file { path = _where.path + '\\' + name, id = this.id, name = name, folder = false, root = _where, link = false, permitWriting = true }; } if (root == null) return false; else { _where.AddComponent(root); _where.CalculateSize(); } } return true; }