private static bool MoveDirectory(string rootDirectory, string directoryNameEntry) { bool success = false; string sourceDirectory = Path.Combine(rootDirectory, directoryNameEntry); string destinationDirectory = Path.Combine(rootDirectory, _UnusedDirectoryName, directoryNameEntry.Substring(0, directoryNameEntry.LastIndexOf('\\'))); if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } Console.WriteLine(" Directory \"{0}\" -> \"{1}\"", sourceDirectory, destinationDirectory); try { string command = "move \"" + sourceDirectory + "\" \"" + destinationDirectory + "\""; // Directory.Move(sourceDirectory, destinationDirectory); string currentDirectory = Directory.GetCurrentDirectory(); success = CommandOperation.RunCommand(currentDirectory, command, CommandOperation.DebugProgress.None, CommandOperation.CommandOutputDisplayType.StandardErrorOnly); } catch (Exception ex) { Console.WriteLine("Exception: Moving directory \"{0}\" to \"{1}\" = \"{2}\"", sourceDirectory, destinationDirectory, ex.ToString()); } return(success); }
static int Main(string[] args) { int error = 0; if (args.Count() < 1) { ShowUsage(); } else { string command = args[0]; for (int argIndex = 1; argIndex < args.Count(); ++argIndex) { string thisParameter = args[argIndex]; if ((thisParameter.Length > 2) && (thisParameter[0] == '/')) { // A switch so just leave it alone command += " " + thisParameter; } else { command += " " + thisParameter.Replace('/', '\\'); } } // for if (command == null) { ShowUsage(); } else { CommandOperation.RunCommand(".\\", command, CommandOperation.DebugProgress.None, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError); } } return(error); }
public bool GitAdd(string sourceRootDirectory, string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; // PVCS Archive Names start with the Archive Drive which ends at the first slash int firstSlashIndex = Name.IndexOf('\\'); if (firstSlashIndex >= 0) { // Found start of relative path string relativePathAndFilename = Name.Substring(firstSlashIndex + 1); string sourceFileFullPath = Path.Combine(sourceRootDirectory, relativePathAndFilename); if (!File.Exists(sourceFileFullPath)) { Console.WriteLine("{0}*** Source File \"{1}\" does not exist", ConsoleDisplay.Indent(indent), sourceFileFullPath); } else { // Source File exists string workfileFullPath = Path.Combine(rootWorkingDirectory, relativePathAndFilename); if (debugProgress == CommandOperation.DebugProgress.Enabled) { Console.WriteLine("{0}Archive Path \"{1}\" working path resolves to \"{2}\"", ConsoleDisplay.Indent(indent), Name, workfileFullPath); } // Find the last slash to pass to xcopy so that it works with a destination directory int lastSlashIndex = workfileFullPath.LastIndexOf('\\'); string workfileDirectory = workfileFullPath.Substring(0, lastSlashIndex + 1); string fullWorkfilePathAndFilename = Path.Combine(workfileDirectory, this.FileName); // Determine the length of the filename without the drive specifier firstSlashIndex = fullWorkfilePathAndFilename.IndexOf('\\'); string fullRootRelativeWorkfilePathAndFilename = fullWorkfilePathAndFilename.Substring(firstSlashIndex + 1); const int longPathAndFilenameLength = 240; if (fullRootRelativeWorkfilePathAndFilename.Length > longPathAndFilenameLength) { Console.WriteLine("{0}+++ Warning: \"{1}\" workfile name is {2} characters long which is longer than {3} characters", ConsoleDisplay.Indent(indent), fullWorkfilePathAndFilename, fullWorkfilePathAndFilename.Length, longPathAndFilenameLength); } string command = String.Format("xcopy \"{0}\" \"{1}\" /v/f/y", sourceFileFullPath, workfileDirectory); // Copy the file into the working directorBy which will cause the file to be "Staged" if (CommandOperation.RunCommand(rootWorkingDirectory, command, debugProgress, CommandOperation.CommandOutputDisplayType.None)) { DateTime dateTimeNow = DateTime.Now; Console.WriteLine("{0}{1} \"{2}\" -> \"{3}\"", ConsoleDisplay.Indent(indent), dateTimeNow.ToString("yyyy-MM-dd-HH:mm:ss"), sourceFileFullPath, workfileDirectory); // Add the file to the Repo success = GitOperation.Add(rootWorkingDirectory, WorkfileRelativePath(rootWorkingDirectory), indent, debugProgress); } else { DateTime dateTimeNow = DateTime.Now; Console.WriteLine("{0} *** {1} Failed \"{2}\" -> \"{3}\"", ConsoleDisplay.Indent(indent), dateTimeNow.ToString("yyyy-MM-dd-HH:mm:ss"), sourceFileFullPath, workfileDirectory); } } // Source File exists } // Found start of relative path return(success); } // GitAdd