Hi,
we have an application that has to do something when copying or moving to a specific folder finishes. How do we handle if a folder has copying or moving process on it in c#
Hi,
we have an application that has to do something when copying or moving to a specific folder finishes. How do we handle if a folder has copying or moving process on it in c#
how do i handle copying to a folder?
Oscarfh
I hope this snippet of code will give you ideas, please feel free to post if this solution is not what you are looking for. Im willing to help you.
ClaudioBello
Thanks for the reply. Copy is done externally either from a local source or by the network, not inside the code. Only the name of the target folder is known, the problem is that how to realize if something(file or folder) is being copied to the target folder at any time.
Thanks
Rafael (Live Butterfly)
Thanks for reply
I think the solution will look like this using System.IO namespace:-
protected void WatchRootDirectory()
{
// Create filesystemwatcher and set property values.
FileSystemWatcher watcher = new FileSystemWatcher("Destination folder");
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Wire events.
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
}
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " changed." );
}
private void watcher_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " created." );
}
private void watcher_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " deleted." );
}
Hope this helps
Rick Hill