동기화 된 드롭 상자 폴더에 항목이 추가 된 후이를 (전체 동기화를 허용하기 위해) 기다렸다가 항목을 이동할 때 감지하는 작은 유틸리티 서비스를 작성하려고합니다. s)를 추가 처리를위한 날짜 스탬프 스테이징 폴더에 저장합니다. 충분히 간단한 ... 여기 보관함이있는 파일 감시자 클래스
내 코드입니다 : 하나 개의 항목이 동기화 된 디렉토리에 추가되는 경우 가static void Main(string[] args)
{
var watcher = new FileSystemWatcher();
string _path = @"E:\IMPORT\Dropbox\";
watcher.Path = _path;
watcher.EnableRaisingEvents = true;
watcher.Created += new FileSystemEventHandler(watcher_Created);
Console
.WriteLine("FileSystemWatcher ready and listening to changes in :\n\n"
+ _path);
watcher.Path = _path;
Console.ReadLine();
}
static void watcher_Created(object sender, FileSystemEventArgs e)
{
Thread.Sleep(3000);
Console.WriteLine(e.Name + " file has been created.");
string filename = Path.GetFileName(e.FullPath);
string path = @"E:\IMPORT\Staging\"
+ DateTime.Now.ToFileTime().ToString()
+ @"\";
try
{
Directory.CreateDirectory(path);
}
catch(Exception ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
try
{
File.Move(e.FullPath, path + filename);
}
catch(Exception ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
}
이 코드는하지만 여러 항목이 추가됩니다 잘 작동 것 및 지연이있을 필요가있다 보관함에 항목을 추가 할 수 있습니다. 내가 이것을 어떻게 성취 할 수 있을지에 대한 아이디어가 있습니까?
지연 이유는 무엇입니까? 준비 폴더가 다시 사용되지 않도록하려면? –
@Austin, 20MB .pdf가 전송되면 드롭 박스 디렉토리에서 완전히 동기화 할 시간이 있습니다. –