1
我試圖寫一個小程序服務,將檢測何時項目(S)已被添加到一個同步的投遞箱文件夾,然後等待(允許完全同步)和移動項目( 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());
}
}
此代碼將正常工作,如果被添加到目錄同步一個項目,但多個項目將被添加,並需要有一個延遲要將項目添加到保管箱。有關我如何完成此任何想法?
爲什麼延遲?所以沒有臨時文件夾被重用? – 2011-12-27 20:18:50
@Austin,所以如果傳輸了20MB的.pdf,它有時間在下拉框目錄中完全同步 – 2011-12-27 20:27:31