|
|
@@ -33,7 +33,6 @@ namespace FileWatcher
|
|
|
|
|
|
timer2.Interval = 1000 * 60 * 60;
|
|
|
timer2.Start();
|
|
|
- RunTran();
|
|
|
}
|
|
|
|
|
|
private void Watcher_Created(object sender, FileSystemEventArgs e)
|
|
|
@@ -45,6 +44,7 @@ namespace FileWatcher
|
|
|
string FullName = e.FullPath;
|
|
|
string Filename = FullName.Substring(FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
string StartPath = FullName.Substring(0, FullName.LastIndexOf(@"\") + 1);
|
|
|
+ Thread.Sleep(1500);
|
|
|
if (File.Exists(FullName))
|
|
|
{
|
|
|
richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff") + " " + e.FullPath + "\n");
|
|
|
@@ -54,8 +54,8 @@ namespace FileWatcher
|
|
|
{
|
|
|
richTextBox1.AppendText("不存在文件" + FullName + "\n");
|
|
|
}
|
|
|
- //不存在同名的文件则进行转换
|
|
|
- if (!File.Exists(StartPath + Filename + ".xls") && File.Exists(FullName))
|
|
|
+ //不存在同名的文件则进行转换,或者Excel文件小于100KB的
|
|
|
+ if ((!File.Exists(StartPath + Filename + ".xls") && File.Exists(FullName)))
|
|
|
{
|
|
|
if (FullName.Substring(FullName.LastIndexOf(".") + 1) == "jdf")
|
|
|
{
|
|
|
@@ -160,24 +160,31 @@ namespace FileWatcher
|
|
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
- Process[] processes1 = Process.GetProcessesByName("DTS-JDFData2Excel");
|
|
|
- for (int i = 0; i < processes1.Length; i++)
|
|
|
+ try
|
|
|
{
|
|
|
- //杀掉超过20秒没关闭的进程
|
|
|
- if (DateTime.Now > processes1[1].StartTime.AddSeconds(20))
|
|
|
+ Process[] processes1 = Process.GetProcessesByName("DTS-JDFData2Excel");
|
|
|
+ for (int i = 0; i < processes1.Length; i++)
|
|
|
{
|
|
|
- processes1[i].Kill();
|
|
|
+ //杀掉超过20秒没关闭的进程
|
|
|
+ if (DateTime.Now > processes1[1].StartTime.AddSeconds(60))
|
|
|
+ {
|
|
|
+ processes1[i].Kill();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- Process[] processes2 = Process.GetProcessesByName("DTS-Data2Excel");
|
|
|
- for (int i = 0; i < processes2.Length; i++)
|
|
|
- {
|
|
|
- if (DateTime.Now > processes2[1].StartTime.AddSeconds(20))
|
|
|
+ Process[] processes2 = Process.GetProcessesByName("DTS-Data2Excel");
|
|
|
+ for (int i = 0; i < processes2.Length; i++)
|
|
|
{
|
|
|
- processes2[i].Kill();
|
|
|
+ if (DateTime.Now > processes2[1].StartTime.AddSeconds(60))
|
|
|
+ {
|
|
|
+ processes2[i].Kill();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void RunTran()
|
|
|
@@ -185,22 +192,20 @@ namespace FileWatcher
|
|
|
try
|
|
|
{
|
|
|
List<FileInfo> lst = new List<FileInfo>();
|
|
|
- string[] path = new string[] { @"D:\PROB-001", @"D:\PROB-002", @"D:\PROB-003", @"D:\PROB-004",
|
|
|
- @"D:\PROB-005", @"D:\PROB-006", @"D:\PROB-007", @"D:\PROB-008", @"D:\PROB-009",
|
|
|
- @"D:\PROB-010", @"D:\PROB-011", @"D:\PROB-012", @"D:\PROB-013", @"D:\PROB-014",
|
|
|
- @"D:\PROB-015", @"D:\PROB-004", @"D:\PROB-016", @"D:\PROB-017", @"D:\PROB-018",
|
|
|
- @"D:\PROB-019", @"D:\PROB-020", @"D:\PROB-021", @"D:\PROB-022", @"D:\PROB-023",
|
|
|
- @"D:\PROB-024", @"D:\PROB-026",@"D:\PROB-027",@"D:\PROB-028",@"D:\PROB-029",
|
|
|
- @"D:\PROB-030",@"D:\PROB-031",@"D:\PROB-032",@"D:\PROB-033",@"D:\PROB-034",
|
|
|
- @"D:\PROB-035",@"D:\PROB-036",@"D:\PROB-037",@"D:\PROB-038",@"D:\PROB-039",
|
|
|
- @"D:\PROB-040",@"D:\PROB-041",@"D:\PROB-042",@"D:\PROB-043",@"D:\PROB-045",@"D:\PROB-046",
|
|
|
- @"D:\PROB-047",@"D:\PROB-048",@"D:\PROB-049",@"D:\PROB-050",@"D:\PROB-051",@"D:\PROB-052",@"D:\PROB-053",
|
|
|
- @"D:\PROB-054",@"D:\PROB-055",@"D:\PROB-056",@"D:\PROB-057",@"D:\PROB-058",@"D:\PROB-059",@"D:\PROB-060",
|
|
|
- @"D:\PROB-061",@"D:\PROB-062",@"D:\PROB-063",@"D:\PROB-064",@"D:\PROB-65",@"D:\PROB-66",@"D:\PROB-067",
|
|
|
- @"D:\PROB-068",@"D:\PROB-069",@"D:\PROB-070",@"D:\PROB-071",@"D:\PROB-072",@"D:\PROB-073",@"D:\PROB-074",
|
|
|
- @"D:\PROB-075",@"D:\PROB-76",@"D:\PROB-077",@"D:\PROB-078",@"D:\PROB-079",@"D:\PROB-080",@"D:\PROB-081",@"D:\PROB-082"};
|
|
|
-
|
|
|
- //string[] path = textBox1.Text.Split(',');
|
|
|
+ string[] path = new string[] { @"D:\PROB-071",@"D:\PROB-072",@"D:\PROB-073",@"D:\PROB-074",
|
|
|
+ @"D:\PROB-075",@"D:\PROB-76",@"D:\PROB-077",@"D:\PROB-078",@"D:\PROB-079",@"D:\PROB-080",@"D:\PROB-081",@"D:\PROB-082",@"D:\PROB-001", @"D:\PROB-002", @"D:\PROB-003", @"D:\PROB-004",
|
|
|
+ @"D:\PROB-005", @"D:\PROB-006", @"D:\PROB-007", @"D:\PROB-008", @"D:\PROB-009",
|
|
|
+ @"D:\PROB-010", @"D:\PROB-011", @"D:\PROB-012", @"D:\PROB-013", @"D:\PROB-014",
|
|
|
+ @"D:\PROB-015", @"D:\PROB-004", @"D:\PROB-016", @"D:\PROB-017", @"D:\PROB-018",
|
|
|
+ @"D:\PROB-019", @"D:\PROB-020", @"D:\PROB-021", @"D:\PROB-022", @"D:\PROB-023",
|
|
|
+ @"D:\PROB-024", @"D:\PROB-026",@"D:\PROB-027",@"D:\PROB-028",@"D:\PROB-029",
|
|
|
+ @"D:\PROB-030",@"D:\PROB-031",@"D:\PROB-032",@"D:\PROB-033",@"D:\PROB-034",
|
|
|
+ @"D:\PROB-035",@"D:\PROB-036",@"D:\PROB-037",@"D:\PROB-038",@"D:\PROB-039",
|
|
|
+ @"D:\PROB-040",@"D:\PROB-041",@"D:\PROB-042",@"D:\PROB-043",@"D:\PROB-045",@"D:\PROB-046",
|
|
|
+ @"D:\PROB-047",@"D:\PROB-048",@"D:\PROB-049",@"D:\PROB-050",@"D:\PROB-051",@"D:\PROB-052",@"D:\PROB-053",
|
|
|
+ @"D:\PROB-054",@"D:\PROB-055",@"D:\PROB-056",@"D:\PROB-057",@"D:\PROB-058",@"D:\PROB-059",@"D:\PROB-060",
|
|
|
+ @"D:\PROB-061",@"D:\PROB-062",@"D:\PROB-063",@"D:\PROB-064",@"D:\PROB-65",@"D:\PROB-66",@"D:\PROB-067",
|
|
|
+ @"D:\PROB-068",@"D:\PROB-069",@"D:\PROB-070"};
|
|
|
for (int i = 0; i < path.Length; i++)
|
|
|
{
|
|
|
richTextBox1.AppendText(path[i] + "\n");
|
|
|
@@ -217,6 +222,19 @@ namespace FileWatcher
|
|
|
richTextBox1.AppendText(shpFile.FullName + "\n");
|
|
|
}
|
|
|
}
|
|
|
+ List<FileInfo> lstFiles1 = getFile(path[i], ".njdf", lst);
|
|
|
+ foreach (FileInfo shpFile in lstFiles1)
|
|
|
+ {
|
|
|
+ string Filename = shpFile.FullName.Substring(shpFile.FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
+ string StartPath = shpFile.FullName.Substring(0, shpFile.FullName.LastIndexOf(@"\") + 1);
|
|
|
+ //不存在同名的文件则进行转换
|
|
|
+ if (!File.Exists(StartPath + Filename + ".xls"))
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ exec(@"D:\FileWatcher\NJDF\DTS-Data2Excel.exe", @"D:\FileWatcher\NJDF\DTS-Data2Excel.exe " + shpFile.FullName);
|
|
|
+ richTextBox1.AppendText(shpFile.FullName + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -225,6 +243,55 @@ namespace FileWatcher
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void RunTran1()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ List<FileInfo> lst = new List<FileInfo>();
|
|
|
+ string[] path = textBox1.Text.Split(',');
|
|
|
+ for (int i = 0; i < path.Length; i++)
|
|
|
+ {
|
|
|
+ richTextBox1.AppendText(path[i] + "\n");
|
|
|
+ List<FileInfo> lstFiles = getFile(path[i], ".jdf", lst);
|
|
|
+ foreach (FileInfo shpFile in lstFiles)
|
|
|
+ {
|
|
|
+ string Filename = shpFile.FullName.Substring(shpFile.FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
+ string StartPath = shpFile.FullName.Substring(0, shpFile.FullName.LastIndexOf(@"\") + 1);
|
|
|
+ //不存在同名的文件则进行转换
|
|
|
+ if ((!File.Exists(StartPath + Filename + ".xls") && (new FileInfo(shpFile.FullName).Length / 1024 > 50)) || (new FileInfo(StartPath + Filename + ".xls").Length / 1024) < 100)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1500);
|
|
|
+ exec(@"D:\FileWatcher\JDF\DTS-JDFData2Excel.exe", @"D:\FileWatcher\JDF\DTS-JDFData2Excel.exe " + shpFile.FullName);
|
|
|
+ richTextBox1.AppendText(shpFile.FullName + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FileInfo> lstFiles1 = getFile(path[i], ".njdf", lst);
|
|
|
+ foreach (FileInfo shpFile in lstFiles1)
|
|
|
+ {
|
|
|
+ string Filename = shpFile.FullName.Substring(shpFile.FullName.LastIndexOf(@"\") + 1).Split('.')[0];
|
|
|
+ string StartPath = shpFile.FullName.Substring(0, shpFile.FullName.LastIndexOf(@"\") + 1);
|
|
|
+ //不存在同名的文件则进行转换
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!File.Exists(StartPath + Filename + ".xls") || (new FileInfo(StartPath + Filename + ".xls").Length / 1024) < 2000)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1500);
|
|
|
+ exec(@"D:\FileWatcher\NJDF\DTS-Data2Excel.exe", @"D:\FileWatcher\NJDF\DTS-Data2Excel.exe " + shpFile.FullName);
|
|
|
+ richTextBox1.AppendText(shpFile.FullName + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ richTextBox1.AppendText(ex.Message + ex.StackTrace + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ richTextBox1.AppendText(ex.Message + ex.StackTrace + "\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
|
|
|
@@ -236,7 +303,6 @@ namespace FileWatcher
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
string[] dir = Directory.GetDirectories(path); //文件夹列表
|
|
|
DirectoryInfo fdir = new DirectoryInfo(path);
|
|
|
FileInfo[] file = fdir.GetFiles();
|
|
|
@@ -267,5 +333,11 @@ namespace FileWatcher
|
|
|
{
|
|
|
RunTran();
|
|
|
}
|
|
|
+
|
|
|
+ private void button1_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Thread tr = new Thread(RunTran1);
|
|
|
+ tr.Start();
|
|
|
+ }
|
|
|
}
|
|
|
}
|