C#和SystemFileWatcher-多个文件
|
我正在使用
FileSystemWatcher
监视文件夹中的新文件。将新文件复制到其中后,对我来说效果很好。但是,如果我复制5个文件(这将是我一次最多可以复制的文件),它将触发,但是FileSystemEventArgs
只有一个文件。
我需要它来传递所有新文件。
有没有办法让它处理所有文件,然后循环浏览它们?
这是我的代码:
static void Main(string[] args)
{
FileSystemWatcher fsw = new FileSystemWatcher(FolderToMonitor)
{
InternalBufferSize = 10000
};
fsw.Created += new FileSystemEventHandler(fsw_Created);
bool monitor = true;
Show(\"Waiting...\", ConsoleColor.Green);
while (monitor)
{
fsw.WaitForChanged(WatcherChangeTypes.All, 2000); // Abort after 2 seconds to see if there has been a user keypress.
if (Console.KeyAvailable)
{
monitor = false;
}
}
Show(\"User has quit the process...\", ConsoleColor.Yellow);
Console.ReadKey();
}`
static void fsw_Created(object sender, FileSystemEventArgs args)
{
Show(\"New File Detected!\", ConsoleColor.Green);
Show(\"New file name: \" + args.Name, ConsoleColor.Green);
bool fileIsReadOnly = true;
while (fileIsReadOnly)
{
Thread.Sleep(5000);
fileIsReadOnly = IsFileReadonly(args.FullPath);
if (fileIsReadOnly)
Show(\"File is readonly... waiting for it to free up...\", ConsoleColor.Yellow);
}
Show(\"File is not readonly... Continuing..\", ConsoleColor.Yellow);
HandleFile(args);
}
没有找到相关结果
已邀请:
2 个回复
担每棱绰
素汞读
}