473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File in use problem

I have a FileSystemWatcher in my application that triggers on file (*.xml)
creation and renaming in a folder. When I detect a new file I should read
it, but sometimes it will fail (file in use).

It is an FTP server that writes the file, so it will create the file and
write to it little by little. So after I detect the file, it can be a while
(time depending on the connection) before it is complete.

QUESTION:
When the file is detected, I want to make sure it is complete and free to
use before I pass it on to the reading function. HOW do I accomplish that? I
have tried two ways:

1. Open it in a FileShare.None mode.
This didn't work, since it actually succeeded sometimes, causing the FTP
server some writing problems, since _I_ locked the file for _HIM_.

2. Monitoring changes in file size.
Didn't work since the file size reported was the file size for a completely
downloaded file and not the partial download.

Any ideas?

- Kristoffer -
Nov 20 '05 #1
6 1115
"Kristoffer Persson" <hidden> schrieb
I have a FileSystemWatcher in my application that triggers on file
(*.xml) creation and renaming in a folder. When I detect a new file I
should read it, but sometimes it will fail (file in use).

It is an FTP server that writes the file, so it will create the file
and write to it little by little. So after I detect the file, it can
be a while (time depending on the connection) before it is
complete.

QUESTION:
When the file is detected, I want to make sure it is complete and
free to use before I pass it on to the reading function. HOW do I
accomplish that? I have tried two ways:

1. Open it in a FileShare.None mode.
This didn't work, since it actually succeeded sometimes, causing the
FTP server some writing problems, since _I_ locked the file for
_HIM_.

2. Monitoring changes in file size.
Didn't work since the file size reported was the file size for a
completely downloaded file and not the partial download.

Any ideas?

- Kristoffer -

No way. Try to open the file in the file mode you need. If you succeed it's
ok, if not, it failed. Sounds simple, but that's how it is. I guess if file
access succeeds, the file has been written completely, but there's no
guarantee. If the FTP server is "clever", it should lock the file til it's
written completely, so succeeding in opening it should be a sign that it's
ready to be processed. But, let's assume the file is created first, then
written into it and it gets closed between the two steps even for a very
short period of time. If you happen to open it just between these two steps,
you've got a problem. So, you must hope for a well designed application
writing the file.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Hi Kristoffer,

Normally I say do not use this for this purpose however you say
When I detect a new file I should read it, but sometimes it will fail (file

in use).

In this case I would make a try, catch and end try with a counter in it and
maybe even something as a *threading.thread.sleep(5000)* in it.

It is maybe dirty however you say , "sometimes" it will fail.

Just my idea about it.

Cor

Nov 20 '05 #3
* "Kristoffer Persson" <hidden> scripsit:
When the file is detected, I want to make sure it is complete and free to
use before I pass it on to the reading function. HOW do I accomplish that? I
have tried two ways:

1. Open it in a FileShare.None mode.
This didn't work, since it actually succeeded sometimes, causing the FTP
server some writing problems, since _I_ locked the file for _HIM_.


Try to open it /with/ file sharing.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c7************@ID-208219.news.uni-berlin.de...
* "Kristoffer Persson" <hidden> scripsit:
When the file is detected, I want to make sure it is complete and free to use before I pass it on to the reading function. HOW do I accomplish that? I have tried two ways:

1. Open it in a FileShare.None mode.
This didn't work, since it actually succeeded sometimes, causing the FTP
server some writing problems, since _I_ locked the file for _HIM_.


Try to open it /with/ file sharing.


Then I wouldn't get the whole file.. OK, I can open it and the FTP server
can write it, but I don't want it until it's complete.

- Kristoffer -
Nov 20 '05 #5
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uJ**************@TK2MSFTNGP10.phx.gbl...
Hi Kristoffer,

Normally I say do not use this for this purpose however you say
Why?
When I detect a new file I should read it, but sometimes it will fail

(file in use).

In this case I would make a try, catch and end try with a counter in it and maybe even something as a *threading.thread.sleep(5000)* in it.


That is what I'm doing now, which is not working...

The thing is that I need to make sure that the file is OK to work with
before I send it to the "file content reader". I should not do the check in
the reader, since it is not my code...

- Kristoffer -
Nov 20 '05 #6
On Wed, 5 May 2004 08:30:22 +0100, Kristoffer Persson wrote:

Any ideas?


Do you have any control over the ftp process? I would reccommend
downloading the file under a temporary name and then rename the file to the
correct name after downloading. That way, the FileSystemWatcher will not
attempt to process the file until it is completely downloaded.

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #7

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

Similar topics

17
23140
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was...
9
3188
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
7
3764
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
11
3579
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
4
11847
by: SS | last post by:
We built an MSI file to deploy a .net app to the workstation. We created an HTML page that has a link to the MSI file. On a very sporadic basis, when the MSI is run we get the following message:...
5
11007
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
8
9699
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
17
7986
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
4
5684
by: pradqdo | last post by:
Hi folks, I have a very strange problem when I try to port my client/server program to cygwin. It is a simple shell program where the server executes client's commands + it can send and receive...
4
4029
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.