I'm monitoring a folder using FileSystemWatcher. If I download a file into there, how do I get the name of that downloaded file? For example, if I downloaded a file named TextFile.txt, how would I have it return that as a string? I am assuming this will work for all four triggers (changed, created, deleted, renamed)? I have IncludeSubdirectories set to true, so it should be able to do that.
File Watcher is an IntelliJ IDEA tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.
The FileSystemWatcher provides us with the event handlers to capture events like renamed, deleted, created and changed.
For example, to watch for renaming of text files, set the Filter property to "*. txt" and call the WaitForChanged method with a Renamed specified for its parameter. The Windows operating system notifies your component of file changes in a buffer created by the FileSystemWatcher.
On the OnCreated
event, add this code:
private void watcher_OnCreated(object source, FileSystemEventArgs e)
{
FileInfo file = new FileInfo(e.FullPath);
Console.WriteLine(file.Name); // this is what you're looking for.
}
See FileInfo Class @ MSDN
private void watcher_OnCreated(object source, FileSystemEventArgs e)
{
String Filename = Path.GetFilename(e.FullPath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With