[AccessD] DIR Command Failing-but not everywhere...

MartyConnelly martyconnelly at shaw.ca
Mon Oct 3 16:35:49 CDT 2005


There are some side effects when Dir is used in certain cases.
You shouldn't use Dir to check for file existence since the Dir
function has the side effect of killing any other Dir loop already running.
May cause "bad things to happen" and much head scratching to trace this.

Also doing it like this will still throw up 68 and 76 errors on 
removeable or missing drive letters

fileexist = Not (Len(Dir(sFileName)) = 0 Or Len(sFileName) = 0)

These methods below will work without throwing up an error on removeable 
drives.

Public Function FileExists(ByVal FileSpec As String) As Boolean
  On Error Resume Next
  FileExists = (GetAttr(FileSpec) And vbDirectory) = vbNormal
End Function


Public Function DriveExists(ByVal DriveSpec As String) As Boolean
  On Error Resume Next
  DriveExists = Len(CurDir$(DriveSpec)) > 0
End Function

'?folderexists("c:\access files") ' either works no need to check for 
trailing slash
'?folderexists("c:\access filesd\")

Public Function FolderExists(ByVal FolderSpec As String) As Boolean
  On Error Resume Next
  FolderExists = (GetAttr(FolderSpec) And vbDirectory) = vbDirectory
End Function

Greg Smith wrote:

>Yahoo!  That was it.  I just changed the code to read to my "D" drive
>(cdrom) here at work and got the same error message.  So my "G" drive at
>home must be one of the cd/dvd drives.  Like I said, happy and dumb at the
>same time... :)
>
>Thanks everyone!!
>
>I'll have to test the drive to make sure it's not a cd/dvd drive. 
>Somehow.  ?  :)
>
>Greg
>
>  
>
>>Ah Hah! That's the one case (?) where Dir() does not just return an
>>empty string. Nice catch.
>>
>>-----Original Message-----
>>From: accessd-bounces at databaseadvisors.com
>>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Conklin
>>Sent: Monday, October 03, 2005 11:08 AM
>>To: 'Access Developers discussion and problem solving'
>>Subject: Re: [AccessD] DIR Command Failing-but not everywhere...
>>
>>
>>That error happens when an existing drive (like a CD Rom ) is emtpy;
>>not-ever-existed drive just returns empty string to DIR.  Are you sure
>>you didn't get new letters assigned from the re-format?  Or plugged in a
>>multi-card reader (SD, CF,etc) that changed/added letters?
>>
>>Steve
>>
>>
>>-----Original Message-----
>>From: accessd-bounces at databaseadvisors.com
>>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin
>>- Beach Access Software
>>Sent: Monday, October 03, 2005 10:49 AM
>>To: Access Developers discussion and problem solving
>>Subject: Re: [AccessD] DIR Command Failing-but not everywhere...
>>
>>Greg:
>>
>>If you have no G: drive at home, wouldn't you expect the Dir command to
>>fail on second one where it's looking for a G drive?
>>
>>Rocky
>>
>>----- Original Message
>>    
>>
>.
>.
>.
>
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list