/// <summary> /// Dirコマンドフォルダーリスト出力 /// </summary> /// <param name="srcpath"></param> /// <param name="exportpath"></param> /// <param name="exclusionFileList"></param> /// <param name="listentime"></param> /// <param name="threadnum"></param> /// <param name="retrynum"></param> /// <param name="retrytime"></param> void CopyListenExclusionFile(string srcpath, string exportpath, List <string> exclusionFileList, string listentime, string threadnum, string retrynum, string retrytime) { StringBuilder dircommand = new StringBuilder(); Process defaultUserDeskTop = new Process(); try { // 配置ファイル名 string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "-" + RandomCode.GetCode(8) + ".log"; string datenowDir = DateTime.Now.ToString("yyyy-MM-dd"); // 今のログパス string logpath = System.AppDomain.CurrentDomain.BaseDirectory + datenowDir + "\\" + fileName; LogFile(logpath); dircommand.Append("robocopy "); dircommand.Append("\"" + srcpath + "\" "); dircommand.Append("\"" + exportpath + "\" "); dircommand.Append(" /MIR "); dircommand.Append(" /MOT:" + listentime + " "); dircommand.Append(" /MT[:" + threadnum + "] "); // ファイル除外 if (exclusionFileList.Count > 0) { string fileExclusionArray = ""; foreach (string folderpath in exclusionFileList) { fileExclusionArray = fileExclusionArray + "*" + folderpath + " "; } dircommand.Append(" /XF " + fileExclusionArray); } dircommand.Append(" /R:" + retrynum + " "); dircommand.Append(" /W:" + retrytime + " "); dircommand.Append(" /LOG+:"); dircommand.Append("\"" + logpath + "\""); dircommand.Append(" /NP /NDL /TEE /XJD /XJF "); // BAT作成 //string batFileName = RandomCode.GetCode(10) + ".bat"; //string batDir = DateTime.Now.ToString("yyyy-MM-dd") + "Bat"; //// 今のプログラムパス //string batPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir + "\\" + batFileName; //CreateBAT batClass = new CreateBAT(batPath); //batClass.Write(dircommand.ToString()); // プロセス設定 defaultUserDeskTop.StartInfo.FileName = "cmd.exe"; defaultUserDeskTop.StartInfo.UseShellExecute = false; defaultUserDeskTop.StartInfo.RedirectStandardInput = true; defaultUserDeskTop.StartInfo.RedirectStandardOutput = true; defaultUserDeskTop.StartInfo.CreateNoWindow = true; defaultUserDeskTop.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; if (defaultUserDeskTop.Start()) { defaultUserDeskTop.StandardInput.WriteLine(dircommand); ProcessIDList.Add(defaultUserDeskTop.Id); } //defaultUserDeskTop.StandardInput.WriteLine("exit"); //defaultUserDeskTop.WaitForExit(); //defaultUserDeskTop.Close(); } catch (Exception ex) { logger.Error(ex.Message); } }
/// <summary> /// Dirコマンドフォルダーリスト出力 /// </summary> /// <param name="srcpath"></param> /// <param name="exportpath"></param> /// <param name="listentime"></param> /// <param name="threadnum"></param> /// <param name="retrynum"></param> /// <param name="retrytime"></param> void CopyListen(string srcpath, string exportpath, string listentime, string threadnum, string retrynum, string retrytime) { StringBuilder dircommand = new StringBuilder(); Process defaultUserDeskTop = new Process(); try { // 配置ファイル名 string fileName = DateTime.Now.ToString("yyyy-MM-dd") + "-" + RandomCode.GetCode(10) + ".log"; string datenowDir = DateTime.Now.ToString("yyyy-MM-dd"); // 今のログパス string logpath = System.AppDomain.CurrentDomain.BaseDirectory + datenowDir + "\\" + fileName; LogFile(logpath); // コマンド処理 dircommand.Append("robocopy "); dircommand.Append("\"" + srcpath + "\" "); dircommand.Append("\"" + exportpath + "\" "); dircommand.Append(" /MIR "); dircommand.Append(" /MOT:" + listentime + " "); dircommand.Append(" /MT[:" + threadnum + "] "); dircommand.Append(" /R:" + retrynum + " "); dircommand.Append(" /W:" + retrytime + " "); dircommand.Append(" /LOG+:"); dircommand.Append("\"" + logpath + "\""); dircommand.Append(" /NP /NDL /TEE /XJD /XJF "); // BAT作成 string batFileName = RandomCode.GetCode(10) + ".bat"; string batDir = DateTime.Now.ToString("yyyy-MM-dd") + "Bat"; // 今のプログラムパス string batPath = System.AppDomain.CurrentDomain.BaseDirectory + batDir + "\\" + batFileName; CreateBAT batClass = new CreateBAT(batPath); batClass.Write(dircommand.ToString()); //// プロセス設定 //defaultUserDeskTop.StartInfo.UserName = "******"; //System.Security.SecureString password = new System.Security.SecureString(); //char[] pass = "******".ToCharArray(); //foreach (char c in pass) //{ // password.AppendChar(c); //} //defaultUserDeskTop.StartInfo.Password = password; // defaultUserDeskTop.StartInfo.FileName = "cmd.exe"; defaultUserDeskTop.StartInfo.UseShellExecute = false; defaultUserDeskTop.StartInfo.RedirectStandardInput = true; defaultUserDeskTop.StartInfo.RedirectStandardOutput = true; defaultUserDeskTop.StartInfo.CreateNoWindow = true; defaultUserDeskTop.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; if (defaultUserDeskTop.Start()) { defaultUserDeskTop.StandardInput.WriteLine(dircommand); ProcessIDList.Add(defaultUserDeskTop.Id); } //defaultUserDeskTop.StandardInput.WriteLine("exit"); //defaultUserDeskTop.WaitForExit(); //defaultUserDeskTop.Close(); } catch (Exception ex) { logger.Error(ex.Message); } }