Solved

File in use

Posted on 2001-06-13
11
180 Views
Last Modified: 2010-05-02
I have a function that overwrites a file.  Is there a way to determine whether the destination file (the one that is overwritten) is in use?

Thanks
0
Comment
Question by:thatsthefactsjac
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 4

Expert Comment

by:beckingh
ID: 6187897
Try to open it and make sure you catch any errors.  If you get an error then the OS couldn't open the file for some reason.  You can probably fiddle with it and determine what the error code for "File in use" is.

It depends on how exactly you are opening the file.

0
 
LVL 3

Expert Comment

by:jrspano
ID: 6187926
some file errors

55 File already open
57 Device I/O error
58 File already exists
59 Bad record length
61 Disk full
62 Input past end of file
63 Bad record number
67 Too many files
68 Device unavailable
70 Permission denied
71 Disk not ready
74 Can't rename with different drive
75 Path/File access error
76 Path not found
0
 
LVL 20

Expert Comment

by:hes
ID: 6187940
On Error Resume Next
Open "c:\test" For Output Lock Read Write As #1
If Err.Number = 70 Then
MsgBox "File in Use"
End If
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6187948
hes, open for input, otherwise if it is there it will be overwritten!!!
0
 

Author Comment

by:thatsthefactsjac
ID: 6188056
I also have several other files that must also be copied.  Is there a way to incorporate these operations into a transaction and rollback if one file copy fails?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Accepted Solution

by:
jrspano earned 50 total points
ID: 6188085
try to open them all first. if you succed then overwrite each one. if it fails don't do your overwrites.
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6188086
You'd probably have to do it manually.  I.e. you could save copies of all the files you are overwriting.  Then if the last copy fails, go back and put back all the original versions.

No way to "rollback" file system changes that I know of.

0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6188466
Note that you can only have 512 open files at a time (this is the limit of the freefile/file number).

Zaphod.
0
 

Author Comment

by:thatsthefactsjac
ID: 6188695
I also have several other files that must also be copied.  Is there a way to incorporate these operations into a transaction and rollback if one file copy fails?
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6189447
Hi!

How about trying to rename the file to something else?

Something like this:

On Error Goto CheckOut
Name "C:\MyFile.txt" As "C:\MyFile.dat"
Name "C:\MyFile.dat" As "C:\MyFile.txt"

CheckOut:
Msgbox "There is an error - probably file in use."
Exit Sub

0
 

Author Comment

by:thatsthefactsjac
ID: 6373005
Thanks for the suggestions!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now