private void RecursiveSearch_NewAndUpdated(string path, string pattern) { string[] folders = System.IO.Directory.GetDirectories(path); string[] patternFiles = System.IO.Directory.GetFiles(path, pattern); Utility.Belt utilBelt = new Utility.Belt(); if (path.Substring(path.Length - 1, 1) != @"\") { path += @"\"; } string minusRootDir = utilBelt.RemoveRootDir(path, this._origDir); if (!Directory.Exists(this._copyDir + minusRootDir)) { Directory.CreateDirectory(this._copyDir + minusRootDir); utilBelt.WriteToFile("Created Directory: " + this._copyDir + minusRootDir); } foreach (string file in patternFiles) { FileInfo fileInfo = new FileInfo(file); if (!System.IO.File.Exists(this._copyDir + minusRootDir + fileInfo.Name.ToString())) { fileInfo.CopyTo(this._copyDir + minusRootDir + fileInfo.Name.ToString()); utilBelt.WriteToFile("Copied: " + file); } else { FileInfo copyFileInfo = new FileInfo(this._copyDir + minusRootDir + fileInfo.Name.ToString()); if ((copyFileInfo.Length != fileInfo.Length) | (copyFileInfo.LastWriteTime != fileInfo.LastWriteTime)) { fileInfo.CopyTo(this._copyDir + minusRootDir + fileInfo.Name.ToString(), true); utilBelt.WriteToFile("Updated: " + file); } } } foreach (string folder in folders) { try { this.RecursiveSearch_NewAndUpdated(folder, "*.*"); } catch (Exception ex) { utilBelt.WriteToFile("Error Occured Opening Folder With Exception: " + ex.ToString()); } } }
private void RecursiveSearch_Deleted(string path, string pattern) { bool okayToProceed = true; string[] folders = System.IO.Directory.GetDirectories(path); string[] patternFiles = System.IO.Directory.GetFiles(path, pattern); Utility.Belt utilBelt = new Utility.Belt(); if (path.Substring(path.Length - 1, 1) != @"\") { path += @"\"; } string minusRootDir = utilBelt.RemoveRootDir(path, this._copyDir); if (!Directory.Exists(this._origDir + minusRootDir)) { Directory.Delete(this._copyDir + minusRootDir, true); okayToProceed = false; utilBelt.WriteToFile("Delted Directory: " + this._copyDir + minusRootDir); } if (okayToProceed) { foreach (string file in patternFiles) { FileInfo fileInfo = new FileInfo(file); if (!System.IO.File.Exists(this._origDir + minusRootDir + fileInfo.Name.ToString())) { fileInfo.Delete(); utilBelt.WriteToFile("Deleted: " + file); } } foreach (string folder in folders) { try { this.RecursiveSearch_Deleted(folder, "*.*"); } catch (Exception ex) { utilBelt.WriteToFile("Error Occured Opening Folder For Deleted Search With Exception: " + ex.ToString()); } } } }