473,686 Members | 2,857 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 10048
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
3863
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
3509
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
14530
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
1715
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
1933
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
1068
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
2459
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
8059
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
2644
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
8261
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
8586
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
8523
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
8942
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...
1
8778
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8781
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
7613
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
6444
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
4538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.