File in use

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
thatsthefactsjacAsked:
Who is Participating?
 
jrspanoCommented:
try to open them all first. if you succed then overwrite each one. if it fails don't do your overwrites.
0
 
beckinghCommented:
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
 
jrspanoCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
hesCommented:
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
 
PaulHewsCommented:
hes, open for input, otherwise if it is there it will be overwritten!!!
0
 
thatsthefactsjacAuthor Commented:
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
 
beckinghCommented:
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
 
Z_BeeblebroxCommented:
Note that you can only have 512 open files at a time (this is the limit of the freefile/file number).

Zaphod.
0
 
thatsthefactsjacAuthor Commented:
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
 
glass_cookieCommented:
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
 
thatsthefactsjacAuthor Commented:
Thanks for the suggestions!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.