|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Testing for "Access Denied" without trying to change the fileWhen a file is being used (e.g. by another program) it is sometimes not
possible to overwrite it, delete it etc. Is there a gentle way to test if it is "Access Denied" without actually trying to overwrite (it and trapping the error)? Because that seems rather like testing if something is glass by hitting it with a hammer. Thanks On Sat, 11 Mar 2006 09:34:02 -0000, "Giles" <giles@nospam.com> wrote: Generally the trick is to open it for binary access, lock read write>When a file is being used (e.g. by another program) it is sometimes not >possible to overwrite it, delete it etc. Is there a gentle way to test if it >is "Access Denied" without actually trying to overwrite (it and trapping the >error)? Because that seems rather like testing if something is glass by >hitting it with a hammer. >Thanks - if that fails then something else has grabbed it Use On Error Resume Next
Show quote
Hide quote
>"J French" wrote Sorry, don't quite get it.> On Sat, 11 Mar 2006 09:34:02 -0000, "Giles" wrote: > >>When a file is being used (e.g. by another program) it is sometimes not >>possible to overwrite it, delete it etc. Is there a gentle way to test if >>it >>is "Access Denied" without actually trying to overwrite (it and trapping >>the >>error)? Because that seems rather like testing if something is glass by >>hitting it with a hammer. >>Thanks > > Generally the trick is to open it for binary access, lock read write > - if that fails then something else has grabbed it > > Use On Error Resume Next Open FPathName For Binary As 1 setattr FPathName,vbreadonly This generates an error because you have just opened it, not because it was in use already. And being in use doesn't prevent opening it for binary. Think I have misunderstood what you mean by lock read write? "Giles" <giles@nospam.com> wrote Open PathName For Binary Lock Read Write As #FileNumber> > Generally the trick is to open it for binary access, lock read write > > - if that fails then something else has grabbed it > > Sorry, don't quite get it. > Open FPathName For Binary As 1 > setattr FPathName,vbreadonly > This generates an error because you have just opened it, not because it was > in use already. And being in use doesn't prevent opening it for binary. > Think I have misunderstood what you mean by lock read write? Check out Open (and FreeFile example) in VB Help... LFS Giles wrote:
> When a file is being used (e.g. by another program) it is sometimes not I see you've already got probably-workable suggestions.> possible to overwrite it, delete it etc. Is there a gentle way to test if it > is "Access Denied" without actually trying to overwrite (it and trapping the > error)? Because that seems rather like testing if something is glass by > hitting it with a hammer. > Thanks > > Personally, I like " Name f As f " with error trapping. I'm not certain it would suit all such uses, but it's been helpful to me in the past. Bob -- |
|||||||||||||||||||||||