473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 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 10036
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vishal | last post by:
hi is there anyway that i can check the size of file on client side before uploading file to server???? suppose the user uploads file of 10 mb then the server will know the size is 10 mb...
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
1
by: Helixpoint | last post by:
I upload a file with the following code. Is there a way to check to see if the file is currently there before I upload? Dim s1 As String Dim s2 As String Dim pos As Integer s1 =...
2
by: mhadi | last post by:
Hello Please Help me!! The big bossman is screaming in my ear, I am only devloper of dotnet in my software house and know only to develop widows based application !! My boss wan't me to...
0
by: Terry | last post by:
Hi All, I'm having trouble checking in new webform or any type of file into ASP.NET web project's root directory. After I added new file into local SourceSafe controlled project, everytime I...
2
by: www.MessageMazes.com | last post by:
Greetings, I'm experimenting with an ASP page that reads data from a file name that is passed to it as a parameter, as in this page, which works, because the "good" file exists. ...
1
by: =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post by:
Hello All, Our application write logs to a file in a folder. Before our application starts writing to that file, I want to check if the current user has write access to that file, for example,...
4
by: giftson.john | last post by:
Hi, I am creating an application which migrates all documents from one repository to another repository. Before migration i have to verify all the documents are unique. No duplicates has to be...
3
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.