-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (49 loc) · 1.84 KB
/
Program.cs
File metadata and controls
51 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace GetFilesFromLQX {
class Program {
static void Main(string[] args) {
Properties.Settings pApp = new Properties.Settings();
string repCible = pApp.fichierCible.Substring(0, pApp.fichierCible.LastIndexOf('\\'));
if (!Directory.Exists(pApp.repDestination)) {
logMessage("Le repertoire destination n'existe pas");
return;
}
// espion sur le fichier source
FileSystemWatcher _watchFile = new FileSystemWatcher(repCible);
// on interviens en cas de changement du fichier
_watchFile.Changed += new FileSystemEventHandler(eventRaised);
// And at last.. We connect our EventHandles to the system API (that is all
// wrapped up in System.IO)
try {
_watchFile.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
catch (Exception ex) {
logMessage(ex.Message, "Erreur");
}
finally {
_watchFile.EnableRaisingEvents = false;
}
}
static void eventRaised(object sender, System.IO.FileSystemEventArgs e) {
// je ne m'interesse qu'a un seul fichier
Properties.Settings pApp = new Properties.Settings();
string fichier = pApp.fichierCible;
string rep = pApp.repDestination;
if(e.FullPath == fichier) {
logMessage("Fichier cible modifié " + e.ChangeType);
// on recopie le fichier dans le rep de destination en le renommant
File.Copy(fichier, string.Format("{0}\\fscore_{1}.txt", rep, DateTime.Now.Ticks));
}
}
static void logMessage(string s, string t = "Normal") {
Console.WriteLine(string.Format("{0} : {2} : {1}", DateTime.Now, s, t));
}
}
}