471,325 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to check if a file is in use?

Hello there, basically I have a little app that goes through a list of files
and renames them according to some selectable options and all I need to know
is how to check if the file is in use by someother process or application
before I attempt to process it. It seems this should be a simple task, but
any help would be appreciated.

Cleave
Jan 12 '06 #1
5 9960
Hi,

"Ken Adams" <ho*********@hotmail.com> wrote in message
news:FYkxf.76982$AP5.60675@edtnps84...
Hello there, basically I have a little app that goes through a list of
files and renames them according to some selectable options and all I need
to know is how to check if the file is in use by someother process or
application before I attempt to process it. It seems this should be a
simple task, but any help would be appreciated.


Your best shoot is trying to rename it, and if an exception is throw , well
then you cannot and go to the next :)

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 12 '06 #2
I know of no way to do this easily, or even conveniently. I have found that
the most optimal way is simply to attempt to perform an operation on the
file, using a Try/Catch. If the operation fails, the Exception will mention
that the file is already in use, and you can handle it by trying again, or
some other means.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Ken Adams" <ho*********@hotmail.com> wrote in message
news:FYkxf.76982$AP5.60675@edtnps84...
Hello there, basically I have a little app that goes through a list of
files and renames them according to some selectable options and all I need
to know is how to check if the file is in use by someother process or
application before I attempt to process it. It seems this should be a
simple task, but any help would be appreciated.

Cleave

Jan 12 '06 #3
Ken Adams wrote:
Hello there, basically I have a little app that goes through a list of files
and renames them according to some selectable options and all I need to know
is how to check if the file is in use by someother process or application
before I attempt to process it. It seems this should be a simple task, but
any help would be appreciated.

Cleave

Get a copy of "handle" from www.sysinternals.com. I don't know if they are
provding source on that one but it shows all files in use!

/steveA

--
Steve Alpert
my email Fgrir_Nycreg @ vqk.pbz is encrypted with ROT13 (www.rot13.org) and spaces

Jan 12 '06 #4
"Steve Alpert" <sr*@newsgroups.nospam> wrote in message
news:uL**************@TK2MSFTNGP14.phx.gbl...
Get a copy of "handle" from www.sysinternals.com. I don't know if they
are provding source on that one but it shows all files in use!


The trouble is, even if you are able to know that it wasn't in-use, it may
become in-use in that instant before you decided to do something with it.
Better to just try it and see if it works.

-- Alan
Jan 12 '06 #5

The trouble is, even if you are able to know that it wasn't in-use, it may
become in-use in that instant before you decided to do something with it.
Better to just try it and see if it works.


exactly, The only way to do it is trying to open it and handling the
exception if not
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by vishal | last post: by
2 posts views Thread by David Fickbohm | last post: by
3 posts views Thread by Chris | last post: by
1 post views Thread by Helixpoint | last post: by
2 posts views Thread by mhadi | last post: by
2 posts views Thread by www.MessageMazes.com | last post: by
1 post views Thread by =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post: by
4 posts views Thread by giftson.john | last post: by

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.