473,915 Members | 7,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10057
Hi,

"Ken Adams" <ho*********@ho tmail.com> wrote in message
news:FYkxf.7698 2$AP5.60675@edt nps84...
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*********@ho tmail.com> wrote in message
news:FYkxf.7698 2$AP5.60675@edt nps84...
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******** ******@TK2MSFTN GP14.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
3873
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 after the file is uploaded to server which wastes the bandwidth so what i want to check is that the server first checks the size of file to upload and if it is o.k. then and then only the file will be uploaded..
2
3524
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 idea how to check a creation date it would be appreciated. Thanks dave def delete_old_files (t:\dm\~\users)
3
14545
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 dialog. The strange thing is that sometimes the save dialogue
1
1728
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 = file1.PostedFile.FileName pos = s1.LastIndexOf("\") + 1 s2 = s1.Substring(pos) file1.PostedFile.SaveAs("C:\Inetpub\wwwroot\xxxxx\images\machines\" & s2)
2
1945
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 devolope a page so that when a user clicks a link to to download a file the page check directory at client side(fixed lets name it "c:\download") and search for file say "blablav1.1.exe" (version will be updated)
0
1080
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 tried to check in new files, the error message box pops up saying "None of the items in the selection are valid for this operation". And then if you try to check in at the project level, the check in dialog box displays only web project file only not...
2
2468
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. http://mazes.com/asp-maze/customized.asp?file=good&firstname=jwk (make "your name is an amazing asp.general programmer" mazes. But when I try this page, with the "bad" file which does not exist, I'm
1
8071
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, "c:\temp\LogFile.txt". I see several articles for setting file access permissions, getting file access permissions for a given user or current user - but the current user could also gain write access to the same file not just by explicit permssion...
4
2655
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 uploaded. Event the document created date, modified date, filename can be different. How to find the document is duplidate. What i did is, i created a file and did save as and saved into another location. I am not able to find that the document...
3
8290
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 the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to Internet Explorer. I cannot check the file size on the web server because IIS throws the following...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9883
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8102
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.