Finding if a file is in use

J

Joe Kimbler

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
 
L

Lifeng Lu

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
 
J

Joe Kimbler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top