473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FileSystemWatcher, determining when the file has been finished copying

Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Michael
Nov 16 '05 #1
5 13671
Trowa,

You have to set the notify filter to know when the file copy is completed.

//set the notify filter
myWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
;

When the notify filter is set, the event wont be fired multiple times. You
will be notify when the entire operation is completed.

Shak.

"Trowa" <Tr***@Barton.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for exclusive access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Michael

Nov 16 '05 #2
Trowa, Shakir,

When I use NotifyFilter, the change event still is fired several times
during a copy process. Is there any other way to determine with
FileSystemWatcher if such a file operation is finished ?

Ulf
Trowa,

You have to set the notify filter to know when the file copy is completed.

//set the notify filter
myWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite ;

When the notify filter is set, the event wont be fired multiple times. You
will be notify when the entire operation is completed.

Shak.

Nov 16 '05 #3
Try this.

myWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;

it should work now

Shak.
"Ulf Bietz" <ul*@nospam.com> wrote in message
news:cb**********@ngspool-d02.news.aol.com...
Trowa, Shakir,

When I use NotifyFilter, the change event still is fired several times
during a copy process. Is there any other way to determine with
FileSystemWatcher if such a file operation is finished ?

Ulf
Trowa,

You have to set the notify filter to know when the file copy is completed.
//set the notify filter
myWatcher.NotifyFilter = NotifyFilters.LastAccess |

NotifyFilters.LastWrite
;

When the notify filter is set, the event wont be fired multiple times. You will be notify when the entire operation is completed.

Shak.


Nov 16 '05 #4
I don't think so!!
The changed event will just fire more than once.
Search from this archive or google, you will find a lot
saying change event will fire more than once.
I just post a question a couple days ago..
Have you really tried that?
Try it, you will see the outcome..
All you can do is use flag and check in a timer_event or comparing trigger time with
last_time_trigger..
Try this.

myWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;

it should work now


Nov 16 '05 #5

Ulf Bietz wrote
Trowa, Shakir,

When I use NotifyFilter, the change event still is fired several times
during a copy process. Is there any other way to determine with
FileSystemWatcher if such a file operation is finished ?


We had a similar issue some time ago. Since we controlled the creation of
the file by ourselves (from another application outside the program that had
to watch the directory), we decided to set

myFileSystemWatcher.NotifyFilter = NotifyFilters.FileName;
myFileSystemWatcher.Renamed += RenamedEventHandler(myRenamedEventDelegate);

and rename the file after copying from the original process. The "renamed"
event will be fired only once. But then, we were in control of the copy
process, maybe you are not. But you might try to rename the file on your own
after receiving each "changed" event. I'm not sure, but I think you cannot
rename a file while it is being copied. If finally the rename is successful,
you can process the "renamed" event.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
2
by: Paul | last post by:
Hi, I've been developing an application in VB.NET that uses the FileSystemWatcher and a popup notification in order to tell me when files have been downloaded. The FileSystemWatcher code in...
1
by: Primo | last post by:
Hello, I am building a data management application with the following processes: Process 1 is a Windows service which uses FileSystemWatcher to monitor a directory. Process 2 opens a file...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
4
by: somequestion | last post by:
Hi, I'm trying to use FileSystemWatcher to determine when a new file has been added to a directory. However, after the file has been added, I need to process the file. This results in a problem...
13
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.