|
|
@@ -16,7 +16,7 @@ namespace FileWatcher
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
- FileWatcher.Path = @"D:\";
|
|
|
+ FileWatcher.Path = @"C:\";
|
|
|
FileWatcher.Filter = "*.jdf";
|
|
|
FileWatcher.EnableRaisingEvents = true;
|
|
|
FileWatcher.Created += new FileSystemEventHandler(Watcher_Created);
|
|
|
@@ -27,51 +27,53 @@ namespace FileWatcher
|
|
|
rk2.SetValue("FileWatcher.exe", path);
|
|
|
rk2.Close();
|
|
|
rk.Close();
|
|
|
+ timer1.Interval = 1800000;
|
|
|
+ timer1.Start();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void Watcher_Created(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
- using (var process = new Process())
|
|
|
+ if (!e.FullPath.Contains("RECYCLE"))
|
|
|
{
|
|
|
- if (!e.FullPath.Contains("RECYCLE"))
|
|
|
+ string FullName = e.FullPath;
|
|
|
+ string Filename = FullName.Substring(FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
+ string StartPath = FullName.Substring(0, FullName.LastIndexOf(@"\") + 1);
|
|
|
+ if (File.Exists(FullName))
|
|
|
{
|
|
|
- string FullName = e.FullPath;
|
|
|
- process.StartInfo.Arguments = @"D:\FileWatcher\DTS-JDFData2Excel.exe " + FullName;
|
|
|
- string Filename = FullName.Substring(FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
- string StartPath = FullName.Substring(0, FullName.LastIndexOf(@"\") + 1);
|
|
|
- if (File.Exists(FullName))
|
|
|
- {
|
|
|
- richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff") + e.FullPath + "\n");
|
|
|
- DoLog(FullName);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- richTextBox1.AppendText("不存在文件" + FullName + "\n");
|
|
|
- }
|
|
|
- //不存在同名的文件则进行转换
|
|
|
- if (!File.Exists(StartPath + Filename + ".xls") && File.Exists(FullName))
|
|
|
- {
|
|
|
- process.StartInfo.FileName = @"D:\FileWatcher\DTS-JDFData2Excel.exe";
|
|
|
- process.StartInfo.UseShellExecute = false;
|
|
|
- process.StartInfo.RedirectStandardInput = true;
|
|
|
- process.StartInfo.RedirectStandardOutput = true;
|
|
|
- process.StartInfo.RedirectStandardError = true;
|
|
|
- process.StartInfo.CreateNoWindow = true;
|
|
|
-
|
|
|
- process.Start();
|
|
|
- process.StandardInput.AutoFlush = true;
|
|
|
- process.StandardInput.WriteLine("exit");
|
|
|
- //获取cmd窗口的输出信息
|
|
|
- string output = process.StandardOutput.ReadToEnd();
|
|
|
-
|
|
|
- process.WaitForExit();
|
|
|
- process.Close();
|
|
|
- }
|
|
|
+ richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff") + e.FullPath + "\n");
|
|
|
+ DoLog(FullName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ richTextBox1.AppendText("不存在文件" + FullName + "\n");
|
|
|
+ }
|
|
|
+ //不存在同名的文件则进行转换
|
|
|
+ if (!File.Exists(StartPath + Filename + ".xls") && File.Exists(FullName))
|
|
|
+ {
|
|
|
+ exec(@"C:\FileWatcher\DTS-JDFData2Excel.exe", @"C:\FileWatcher\DTS-JDFData2Excel.exe " + FullName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void DoLog(string Message)
|
|
|
+ public void exec(string exePath, string parameters)
|
|
|
+ {
|
|
|
+ Process process = new System.Diagnostics.Process();
|
|
|
+ process.StartInfo.FileName = exePath;
|
|
|
+ process.StartInfo.Arguments = parameters;
|
|
|
+ process.StartInfo.UseShellExecute = false;
|
|
|
+ process.StartInfo.CreateNoWindow = true;
|
|
|
+ process.StartInfo.RedirectStandardOutput = true;
|
|
|
+ process.BeginOutputReadLine();
|
|
|
+ process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DoLog(string Message)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -138,5 +140,14 @@ namespace FileWatcher
|
|
|
throw ex;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void timer1_Tick(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Process[] processes1 = Process.GetProcessesByName("DTS-JDFData2Excel");
|
|
|
+ for (int i = 0; i < processes1.Length; i++)
|
|
|
+ {
|
|
|
+ processes1[i].Kill();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|