By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

How do you detect when a file is finished being created

P: n/a
Hello,

I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in the
directory and starts a process that decrypts it and parses the resulting
contents. I am using the FileSystemWatcher's Created event to detect when
the file arrives. The problem I have is that these files are large(5-10
megs) and they are being transfered over a limited pipe. I don't want to
start the decryption and parsing until they are done downloading but I can't
seem to find a straightforward way of sorting out when that is. The
FileSystemWatcher Created event fires off as soon as the file starts to hit
the directory and it kicks off my other processes to early.

Does anyone have a way to determine when the file is done loading? (note -
I have no idea how long the file will take to download or how big it may be.)

Thanks for any help,
Doug
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On the old unix systems I would check the filesize in a loop, filesize ==
same after a few times I figured the file was complete. I'm sure .NET has
some class, methods to do this?

"Doug R" <Do***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,

I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in the directory and starts a process that decrypts it and parses the resulting
contents. I am using the FileSystemWatcher's Created event to detect when
the file arrives. The problem I have is that these files are large(5-10
megs) and they are being transfered over a limited pipe. I don't want to
start the decryption and parsing until they are done downloading but I can't seem to find a straightforward way of sorting out when that is. The
FileSystemWatcher Created event fires off as soon as the file starts to hit the directory and it kicks off my other processes to early.

Does anyone have a way to determine when the file is done loading? (note - I have no idea how long the file will take to download or how big it may be.)
Thanks for any help,
Doug

Jul 21 '05 #2

P: n/a
I was hoping to avoid that aproach if I could. Part of the problem with it
is that the downloads can temporarily stall causing a false positive. That
would also require me to build it as a multithreaded system and it is quite
happily single threaded at the moment.

"Jim Douglas" wrote:
On the old unix systems I would check the filesize in a loop, filesize ==
same after a few times I figured the file was complete. I'm sure .NET has
some class, methods to do this?

"Doug R" <Do***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hello,

I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in

the
directory and starts a process that decrypts it and parses the resulting
contents. I am using the FileSystemWatcher's Created event to detect when
the file arrives. The problem I have is that these files are large(5-10
megs) and they are being transfered over a limited pipe. I don't want to
start the decryption and parsing until they are done downloading but I

can't
seem to find a straightforward way of sorting out when that is. The
FileSystemWatcher Created event fires off as soon as the file starts to

hit
the directory and it kicks off my other processes to early.

Does anyone have a way to determine when the file is done loading?

(note -
I have no idea how long the file will take to download or how big it may

be.)

Thanks for any help,
Doug


Jul 21 '05 #3

P: n/a
Not familiar with it but what if you check the changed event ? Also once you
have no more changed event for a period of time you could perhaps try to
open the file with an exclusive lock for an additonal check.

Patrice

--

"Doug R" <Do***@discussions.microsoft.com> a écrit dans le message de
news:8A**********************************@microsof t.com...
Hello,

I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in the directory and starts a process that decrypts it and parses the resulting
contents. I am using the FileSystemWatcher's Created event to detect when
the file arrives. The problem I have is that these files are large(5-10
megs) and they are being transfered over a limited pipe. I don't want to
start the decryption and parsing until they are done downloading but I can't seem to find a straightforward way of sorting out when that is. The
FileSystemWatcher Created event fires off as soon as the file starts to hit the directory and it kicks off my other processes to early.

Does anyone have a way to determine when the file is done loading? (note - I have no idea how long the file will take to download or how big it may be.)
Thanks for any help,
Doug

Jul 21 '05 #4

P: n/a
Hi Doug

I ran into the same problem in my filewatcher. I made a function that
checked if the file was open
if the function was true then it waited and then tried again until the file
was ready.

Private Function isFileOpen(ByVal filename As String) As Boolean

Dim sf As System.IO.FileStream

Try

sf = System.IO.File.Open(filename, System.IO.FileMode.Open,
System.IO.FileAccess.ReadWrite, System.IO.FileShare.None)

Return False

Catch ex As System.IO.IOException

Return True

ex = Nothing

Finally

'

If Not IsNothing(sf) Then

sf.Close()

sf = Nothing

End If

End Try

End Function

And in the code do an DO loop as follow

Do

System.Threading.Thread.Sleep(500)

Loop While wfile.Exists(file_name) And isFileOpen(file_name)

I hope this helps

Petter L.

"Patrice" <no****@nowhere.com> wrote in message
news:OC**************@TK2MSFTNGP14.phx.gbl...
Not familiar with it but what if you check the changed event ? Also once
you
have no more changed event for a period of time you could perhaps try to
open the file with an exclusive lock for an additonal check.

Patrice

--

"Doug R" <Do***@discussions.microsoft.com> a écrit dans le message de
news:8A**********************************@microsof t.com...
Hello,

I could use a little help from you Gurus out there. I have an aplication
that watches a directory and detects when a PGP encrypted file lands in

the
directory and starts a process that decrypts it and parses the resulting
contents. I am using the FileSystemWatcher's Created event to detect
when
the file arrives. The problem I have is that these files are large(5-10
megs) and they are being transfered over a limited pipe. I don't want to
start the decryption and parsing until they are done downloading but I

can't
seem to find a straightforward way of sorting out when that is. The
FileSystemWatcher Created event fires off as soon as the file starts to

hit
the directory and it kicks off my other processes to early.

Does anyone have a way to determine when the file is done loading?

(note -
I have no idea how long the file will take to download or how big it may

be.)

Thanks for any help,
Doug


Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.