[AccessD] Creating Subdirectories Solved

Jurgen Welz jwelz at hotmail.com
Mon Oct 20 16:04:39 CDT 2008


I'm not sure what it is that you have discovered to be the problem.  For your information, the vbDirectory parameter in the Dir function does not limit the return strings to directories.  For example, from the debug window, if I have a file named Omdata.mdb on my S drive in a folder named GOM, executing the following:

?dir("S:\GOM\omdata.mdb", vbDirectory)
returns the file name:
OmData.mdb

In order to check whether the return string is in fact a folder, you should probably check the attributes:

?getattr("S:\GOM\Omdata.mdb") and vbDirectory
Returns 0 or false.

?getattr("S:\GOM") and vbDirectory
Returns 16 which evaluates to true.

?getattr("S:\GOM\") and vbDirectory
Adding the trailing '\' also evaluates to 16 or true.

?dir("S:\GOM")
returns nothing whereas

?dir("S:\GOM\")
returns the first file in the folder as though you used the wild cards '*.*"

?dir("S:\GOM\", vbDirectory)
returns a '.', a decimal that is a nonzero length string that represents a folder at a lower level.

?dir("S:\GOM", vbDirectory)
Returns the folder name, 'GOM'

To prevent confusion with files that have the same name as a folder, you pretty much need tto test with GetAttr.  You would be wise to check for any other files in the folder before you delete them also.  My preference is to send files to the recycle bin rather than Kill them.  The Kill method just deletes the file with no recycle bin capability.

According to your last post, you added, wrapped in Len():

?dir("C:\", vbDirectory)

The problem is, that will always return the first file name in the C root directory.  That will always have a length and has no viaable possible purpose if that is literally your test.  Not knowing the difference between your hard coded path string and the contents of PDrive, I don't see how this has any bearing on your ability to delete a folder.  No 'Of course you....' from me.

You would be better off checking for the specific file string as a return rather than the length of an unknown return and the existence of any other return strings (call dir in a loop using the string parameter at the outset of the loop).

Sorry, but I don't believe you've spent enough time on this yet, but I'd hardly call it wasted if you wind up learning anthing from the exercise.

Ciao
Jürgen Welz
Edmonton, Alberta
jwelz at hotmail.com

> Date: Mon, 20 Oct 2008 08:47:13 -0700
> From: iggy at nanaimo.ark.com
> To: accessd at databaseadvisors.com
> Subject: [AccessD] Creating Subdirectories Solved
>
> Hey All
> Just thought I would share this (some of you will probably say "Of
> course you twit that was the problem"). Way too much time wasted on this
> one.
> Pulled the code apart,checked the path string etc. etc etc. and discovered.
> Len(Dir(Trim(PDrive), vbDirectory)) was causing the problem.
>
> MkDir Trim(PDrive)
> If Len(Dir(Trim(PDrive), vbDirectory)) = 0 Then
> DoCmd.Beep
> MsgBox "Sorry cannot create this path - " & PDrive & ". Please
> check that you have access rights...", 48, "Message"
> Exit Sub
> End If
>
> I added this and I no longer get error messages and the folder deleted
> no problem.
> If Len(Dir("C:\", vbDirectory)) = 0 Then
> End If
>
> Further down in the code I had something similiar
> If len(dir(trim(PDrive) & "Data.mdb")) = 0 then
> to see if the data.mdb existed, if not place a clean copy in the
> folder/directory, had the same delete problem until I changed my code
> logic.

_________________________________________________________________





More information about the AccessD mailing list