I'm trying to know if there are new files created in a given directory. I have next code:
private static void CreateWatcher()
{
//Create a new FileSystemWatcher.
FileSystemWatcher watcher = new FileSystemWatcher();
//Set the filter to all files.
watcher.Filter = "*.*";
//Subscribe to the Created event.
watcher.Created += new FileSystemEventHandler(watcher_FileCreated);
//Set the path
watcher.Path = path;
//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}
private static void watcher_FileCreated(object sender, FileSystemEventArgs e)
{
Console.WriteLine("Nuevo archivo creado -> " + e.Name);
}
public static void Main(string[] args)
{
CreateWatcher();
CreateFiles();
Console.Read();
}
In CreatedFiles()
function, I'm creating on the path three new files (one zip and two txt). It detects two txt files but not the same with the zip file. How can I solve that?