×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Test for file open by another app ?

Test for file open by another app ?

Test for file open by another app ?

(OP)
Is there an easy way to test to see if a file is currently open by another application ? I am working on a VB project that requires the file to not be open before I access it. (I am using DSOFile (from Microsoft) to access document properties)

RE: Test for file open by another app ?

Hi,
This is not a Professional solution !.
You know that if a file is already opened, it could not be deleted. So you can copy the file to a temporary one and try deleting the original file , if the delete operation failed, this mean that the file is used by another app. , if delete success rename the Temp. file to real name and countinue working on it .

RE: Test for file open by another app ?

(OP)
DimSH;
I want to thank you for the tip. Nobody else was willing to try this one, but you were ! Although I think it's a little risky to be deleting Soldworks files while someone has them open, you were the only one that responded. Thanks again.
Don Michaels

RE: Test for file open by another app ?

You could try this:

on error resume next
Open "MYFILE.TXT" For Output Lock Read Write As #iHandle
if err.number <> 0 then
     'THE FILE IS IN USE
else
    CLOSE #iHandle
    KILL file.txt"
endif
on error goto 0

What the above snippet does is to try an lock a file. This will fail if the fail is already locked by another application. You need to keep in mind that some applications don't lock the files, so there is no indication that the file is in use.


Troy Williams
fenris@hotmail.com

RE: Test for file open by another app ?

If you are opening the file:
Open the file and check to see if it's Read-Only.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: Test for file open by another app ?

Just go ahead and kill the file and trap the error if it happens:

--Start of snippit

Public Sub RemoveFile (strFileName as String)
On error goto fileError
   Kill strFileName
   goto hurrah

fileError:
   if err.number = 75 then
       'file/path error - probably in use

   else
       'something else went kaka-kookoo, mebbe we'll throw
       ' it back up the call stack and make it someone
       ' elses problem
       err.Raise err.Number, err.Source, _
         err.Description, err.HelpFile, err.HelpContext
   end if
   err.clear

hurrah:

end sub
---END of snippit

No true coder likes goto statements, but Uncle Bill makes us use 'em anyways.  If the file isn't locked, then the app doesn't really have it 'open'.  It just read it, and will probably re-write it completely on a save.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close