public static void RenameFile() { //Trace.WriteLine("current directory \"{0}\"", Directory.GetCurrentDirectory()); bool recurseDir = false; bool simulate = true; bool moveFile = false; string printFile = null; foreach (string opt in _options) { if (opt == "-r") simulate = false; if (opt == "-s") simulate = true; if (opt == "-m") moveFile = true; if (opt == "-nm") moveFile = false; if (opt.StartsWith("-n:")) printFile = opt.Substring(3); } Trace.Write("rename file ("); if (simulate) Trace.Write("simulate"); else Trace.Write("real"); if (moveFile) Trace.Write(" rename and move file"); else Trace.Write(" rename file"); Trace.Write(") "); foreach (string arg in _args) Trace.Write(" {0}", arg); if (printFile != null) Trace.Write(" name:\"{0}\"", printFile); Trace.WriteLine(); //Trace.WriteLine("init PrintManager start"); PrintManager_v1 pm = new PrintManager_v1(_config.GetElement("Print")); //Trace.WriteLine("init PrintManager end"); SearchOption option = SearchOption.TopDirectoryOnly; if (recurseDir) option = SearchOption.AllDirectories; string dir = "."; string filePattern = "*.pdf"; if (_args.Length > 0) { filePattern = _args[0]; string dir2 = zPath.GetDirectoryName(filePattern); if (dir2 != "") dir = dir2; filePattern = zPath.GetFileName(filePattern); } //Trace.WriteLine("read directory start"); string[] files = zDirectory.GetFiles(dir, filePattern, option); //Trace.WriteLine("read directory end"); if (printFile != null && files.Length > 1) throw new PBException("can't use option name with more than one file"); if (files.Length == 0) Trace.WriteLine("file not found"); foreach (string file in files) { try { //Trace.WriteLine("RenameFile start"); pu1.RenameFile(pm, file, simulate, moveFile, printFile); //Trace.WriteLine("RenameFile end"); } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } } }
public static void RenameFile() { //Trace.WriteLine("current directory \"{0}\"", Directory.GetCurrentDirectory()); bool recurseDir = false; bool simulate = true; bool moveFile = false; string printFile = null; foreach (string opt in _options) { if (opt == "-r") { simulate = false; } if (opt == "-s") { simulate = true; } if (opt == "-m") { moveFile = true; } if (opt == "-nm") { moveFile = false; } if (opt.StartsWith("-n:")) { printFile = opt.Substring(3); } } Trace.Write("rename file ("); if (simulate) { Trace.Write("simulate"); } else { Trace.Write("real"); } if (moveFile) { Trace.Write(" rename and move file"); } else { Trace.Write(" rename file"); } Trace.Write(") "); foreach (string arg in _args) { Trace.Write(" {0}", arg); } if (printFile != null) { Trace.Write(" name:\"{0}\"", printFile); } Trace.WriteLine(); //Trace.WriteLine("init PrintManager start"); PrintManager_v1 pm = new PrintManager_v1(_config.GetElement("Print")); //Trace.WriteLine("init PrintManager end"); SearchOption option = SearchOption.TopDirectoryOnly; if (recurseDir) { option = SearchOption.AllDirectories; } string dir = "."; string filePattern = "*.pdf"; if (_args.Length > 0) { filePattern = _args[0]; string dir2 = zPath.GetDirectoryName(filePattern); if (dir2 != "") { dir = dir2; } filePattern = zPath.GetFileName(filePattern); } //Trace.WriteLine("read directory start"); string[] files = zDirectory.GetFiles(dir, filePattern, option); //Trace.WriteLine("read directory end"); if (printFile != null && files.Length > 1) { throw new PBException("can't use option name with more than one file"); } if (files.Length == 0) { Trace.WriteLine("file not found"); } foreach (string file in files) { try { //Trace.WriteLine("RenameFile start"); pu1.RenameFile(pm, file, simulate, moveFile, printFile); //Trace.WriteLine("RenameFile end"); } catch (Exception ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } } }