469,348 Members | 1,682 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,348 developers. It's quick & easy.

Finding if a file is in use

I'm writing a "Hot Directory" software package that watches for an MP3
file to be uploaded to an FTP directory. When the file has completed
uploading, it will be converted into a WAV file and imported into an
automation system.

The problem that I am having is telling if IIS (FTP) is done uploading
the file and it is no longer in use. Currently, the software just
checks the file time. If the time is older than 5 minutes, the
software converts the file. This works great for our staff with
high-speed internet connections. However, if a staff member uploads
an MP3 using a 56k line, it may take longer than 5 minutes to upload.
When the software scans the file and sees it's older than 5 minutes
and starts to convert it, the software crashes.

I've tried using the "LanManServer" object to check if a file is open.
However, going from XP to a Windows 2000 server, it doesn't seem to
work.

I've also tried to use the Try/Catch functions. This almost works.
However, for some reason the last second of each file is clipped when
converted. It almost acts like IIS no longer reports the file in use,
but it hasn't written the last block of the MP3 file yet.

I'm wondering if there is a function or compnent that someone has that
will check if a file is in use either on a local machine, or on
another machine on the LAN.

Thanks.

-Joe Kimbler
Nov 20 '05 #1
3 1729

I don't know whether the FTP server keeps the file open or only open the
file when it writes. If it keeps openning the file, you can open the file
with NonShareMode, so you won't be able to open it until FTP close it. If
FTP closes the file in IDLE time, and reopens it when necessary.

You might have to use your old way -- to check last modify timestamp of
the file. If 5 minutes are not longer enough, you have to pick up another
value. It is still possible a file is clipped. But your program could
convert the file again when it is updated again.

However, some error handles in your program are always necessary, since
the connection between client/server could be lost when half of the file
was uploaded. You never want your app crash after that.

Lifeng
MS VB

Nov 20 '05 #2
True enough. However, the main problem with this is that the file is
"timestamped" with the time at Creation...not when modified, unless
you know a way to access the "last modified" time? I've looked all
over and havn't found anything yet.

If I could access the "Last Modified" timestamp, I could tell the
software to only wait two minutes rather than 5 since the "last
modified" time will move with the FTP Server writing to the file.

-Joe

On Thu, 20 Nov 2003 21:06:23 GMT, no****@nospam.net (Lifeng Lu) wrote:

You might have to use your old way -- to check last modify timestamp of
the file. If 5 minutes are not longer enough, you have to pick up another
value. It is still possible a file is clipped. But your program could
convert the file again when it is updated again.


Nov 20 '05 #3
Try System.IO.File.GetLastWriteTime

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Noam Dekers | last post: by
1 post views Thread by D. Alvarado | last post: by
15 posts views Thread by Benjamin Rutt | last post: by
8 posts views Thread by Rick Strahl [MVP] | last post: by
1 post views Thread by avik1612 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.