Home All Groups Group Topic Archive Search About

Why ?? (Path/File access error (Error 75)

Author
10 Mar 2006 7:53 PM
Robertico
Why causes next code a Path/File access error (Error 75)  ??

    Private Sub Command1_Click()
        MyFile = Dir("c:\temp\1\*.JPG")
        MsgBox MyFile

        OldName = "c:\temp\1": NewName = "c:\temp\5"
        Name OldName As NewName
    End Sub

And not without :

        MyFile = Dir("c:\temp\1\*.JPG")
        MsgBox MyFile

What can i do to use both ?

Regards,

Robertico

Author
10 Mar 2006 9:05 PM
Tony Proctor
The Dir$() command has the nasty habit of locking the directory being
searched until that search has been exhausted (i.e. until an empty name is
returned)

One way to get around it is to insert a call to Dir$("nul"). For instance:

     Private Sub Command1_Click()
         MyFile = Dir("c:\temp\1\*.JPG")
        Call Dir("nul")
         MsgBox MyFile

This changes the search to the special 'null device' and so removes the
lock. Also, it doesn't impose any new lock on the null device.

        Tony proctor

Show quoteHide quote
"Robertico" <Robertico@nomail.notvalid> wrote in message
news:uRKlRxHRGHA.5500@TK2MSFTNGP12.phx.gbl...
> Why causes next code a Path/File access error (Error 75)  ??
>
>     Private Sub Command1_Click()
>         MyFile = Dir("c:\temp\1\*.JPG")
>         MsgBox MyFile
>
>         OldName = "c:\temp\1": NewName = "c:\temp\5"
>         Name OldName As NewName
>     End Sub
>
> And not without :
>
>         MyFile = Dir("c:\temp\1\*.JPG")
>         MsgBox MyFile
>
> What can i do to use both ?
>
> Regards,
>
> Robertico
>
>
Author
11 Mar 2006 6:23 AM
Robertico
This is not only a "Dir" problem. Is there some general "NUL" solution to
"unlock" files.
I have the same problem after reading and closing a database (mdb) file.
If the file is closed, it's possible to rename the file, but it's parent
directory is still in use ???

Robertico
Author
11 Mar 2006 8:01 AM
Robertico
More specific (did some tests):

I used the "Common Dialog GetOpenFileName API" (from http://vbnet.mvps.org/)
to retrieve a filename.
From then the whole directory to that file is in use, without reading the
file or what.
Windows can't rename the directories as long as my app runs.

Is it possible to "unlock" the directories ?

Robertico
Author
11 Mar 2006 10:13 AM
Tony Proctor
I reproduced it here, and the problem was Dir(). The extra Dir() call fixed
it here

    Tony Proctor

Show quoteHide quote
"Robertico" <Robertico@nomail.notvalid> wrote in message
news:O18UARNRGHA.4952@TK2MSFTNGP09.phx.gbl...
> This is not only a "Dir" problem. Is there some general "NUL" solution to
> "unlock" files.
> I have the same problem after reading and closing a database (mdb) file.
> If the file is closed, it's possible to rename the file, but it's parent
> directory is still in use ???
>
> Robertico
>
>
Author
11 Mar 2006 12:29 PM
Robertico
Tony,

What do you mean with:
>I reproduced it here, and the problem was Dir(). The extra Dir() call fixed
>it here

Did you tried it with the "Common Dialog GetOpenFileName API" ?

Robertico
Author
11 Mar 2006 2:30 PM
Tony Proctor
No, but that is unrelated Robertico. I merely gave you a solution to the
problem you originally posted.

I have heard that the Common Dialog control also locks a directory, but I
believe this is because, by default, it makes the selected directory the
'current working directory. Although I can't confirm it myself, I have heard
others suggest that setting the cdlOFNNoChangeDir option on the control
prevents this.

    Tony Proctor

Show quoteHide quote
"Robertico" <Robertico@nomail.notvalid> wrote in message
news:uHwe6dQRGHA.256@TK2MSFTNGP14.phx.gbl...
> Tony,
>
> What do you mean with:
> >I reproduced it here, and the problem was Dir(). The extra Dir() call
fixed
> >it here
>
> Did you tried it with the "Common Dialog GetOpenFileName API" ?
>
> Robertico
>
>
Author
11 Mar 2006 2:57 PM
Robertico
Tony,

>... Although I can't confirm it myself, I have heard
> others suggest that setting the cdlOFNNoChangeDir option on the control
> prevents this.

Thanks a lot !!....cdlOFNNoChangeDir did the job.

Robertico
Author
10 Mar 2006 10:07 PM
AGP
straight from the Help:


Renames a disk file, directory, or folder.

Syntax

Name oldpathname As newpathname

The Name statement syntax has these parts:

Part Description
oldpathname Required.String expression that specifies the existing file
name and location - may include directory or folder, and drive.
newpathname Required. String expression that specifies the new file
name and location - may include directory or folder, and drive. The
file name specified by newpathname can't already exist.


Remarks

The Name statement renames a file and moves it to a different directory
or folder, if necessary. Name can move a file across drives, but it can
only rename an existing directory or folder when both newpathname and
oldpathname are located on the same drive. Name cannot create a new
file, directory, or folder.

Using Name on an open file produces an error. You must close an open
file before renaming it. Namearguments cannot include
multiple-character (*) and single-character (?) wildcards.