public string ComputeTargetDirectoryFromSourceDirectory(string targetDir, string srcBaseDirectory, DirectoryInfo currDirectory) { var u = new HelperUtility(); var baseTarget = u.ConvertStringPathToInfo(u.RemoveTrailingDirectorySlash(targetDir)); if(baseTarget==null) { _log.LogAndDisplay(String.Format("Invalid Directory Info For: {0}",targetDir),LoggerMode.LogAndDisplayConsoleLine); return null; } var baseSource = u.ConvertStringPathToInfo(u.RemoveTrailingDirectorySlash(srcBaseDirectory)); if(baseSource==null) { throw new Exception(String.Format("Invalid Source Directory Info: {0}",srcBaseDirectory)); } var relDir = u.RemoveTrailingDirectorySlash(currDirectory.FullName.Remove(0, baseSource.FullName.Length)); return baseTarget.FullName + relDir; }
private void DoCopyCommand(CopyFileCommand cmd, string currSourceDir) { var uF = new FileUtility(_log); var uH = new HelperUtility(); var currSrcInfo = uH.ConvertStringPathToInfo(currSourceDir); if(currSrcInfo==null) { throw new Exception(String.Format("Invalid Srouce Directory Info: {0}", currSourceDir)); } var newTargetDir = uF.ComputeTargetDirectoryFromSourceDirectory(cmd.TargetDirectory,cmd.SourceDirectory, currSrcInfo); if(newTargetDir == null) { return; } if(!Directory.Exists(newTargetDir)) { try { Directory.CreateDirectory(newTargetDir); } catch(Exception e) { _log.LogAndDisplay(String.Format("Error Creating Target Directory: {0}",newTargetDir),e,LoggerMode.LogAndDisplayConsoleLine); return; } } var newTargInfo = uH.ConvertStringPathToInfo(newTargetDir); if(newTargInfo==null) { _log.LogAndDisplay(String.Format("Invalid Target Directory Info: {0}", newTargetDir),LoggerMode.LogAndDisplayConsoleLine); return; } _log.DisplayCopyDirectoryStatus(currSrcInfo.FullName, newTargInfo.FullName); AssignCopyOperationByCopyMode(cmd, currSrcInfo, newTargInfo); if(!cmd.CommandParameters.CopySubdirectories) { return; } var dirs = currSrcInfo.GetDirectories(); if(dirs.Length < 1) { return; } foreach (var dir in dirs) { DoCopyCommand(cmd, uH.RemoveTrailingDirectorySlash(dir.FullName)); } }
public IList<DirectoryInfo> GetAllDirectoriesInTree(string topDirectory) { var u = new HelperUtility(); if(string.IsNullOrEmpty(topDirectory)) { _log.DisplayToConsole(string.Format("Top Directory is NULL/Empty: {0}", topDirectory), LoggerMode.LogAndDisplayConsoleLine); return null; } var dInfo = u.ConvertStringPathToInfo(topDirectory); if(dInfo==null) { _log.DisplayToConsole(string.Format("Top Directory Info Object is Invalid: {0}", topDirectory), LoggerMode.LogAndDisplayConsoleLine); return null; } IList<DirectoryInfo> dirInfoTree = new List<DirectoryInfo>(); GetAllDirectoriesInTree(dInfo, dirInfoTree); return dirInfoTree; }
public void DeleteAllFilesInDirectoryTree(string dirTree) { var u = new HelperUtility(); var dInfoTopdir = u.ConvertStringPathToInfo(dirTree); if(dInfoTopdir==null) { return; } DeleteAllFilesInDirectoryTree(dInfoTopdir); }