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 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
Run();
}
public static void Run()
{
FileSystemWatcher Watcher = new FileSystemWatcher();
Watcher.Path = @"C:\dwn";
Console.WriteLine("Sureveillance du repertoire : " + Watcher.Path);
Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
Watcher.Filter = "*.csv";
Watcher.Created += new FileSystemEventHandler(OnChanged);
Watcher.EnableRaisingEvents = true;
Console.WriteLine("Appuyer \'q\' pour quitter... ");
while (Console.Read() != 'q') ;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
string targetgls = @"C:\gls1";
string targetposte = @"C:\poste";
string filename = e.Name;
string debut = filename.Substring(0, 3);
string origine = e.FullPath;
Console.WriteLine("Fichier " + e.FullPath + " " + e.ChangeType);
Console.WriteLine("Fichier : " + origine);
if (debut == "lap")
{
System.IO.File.Copy((e.FullPath), targetposte);
Console.WriteLine("Fichier copier dans le repertoire poste");
System.IO.File.Delete(e.FullPath);
Console.WriteLine("Fichier supprimer du repertoire : " + e.FullPath);
}
if (debut == "gls")
{
Console.WriteLine("Fichier copier dans le repertoire gls");
System.IO.File.Move((e.FullPath), targetgls + "\\" + filename);
}
}
}
} |
Partager