sub directories

  • Thread starter Thread starter Mike
  • Start date Start date
Mike,

Sub test()
Const cDir = "C:\", cSubDir = "WINDOWS"

Dim strTemp As String

strTemp = Dir(cDir, vbDirectory)
Do Until strTemp = "" Or strTemp = cSubDir
strTemp = Dir
Loop
If strTemp = cSubDir Then
MsgBox "SubDir Found"
Else
MsgBox "SubDir Not Found"
End If
End Sub

Rob
 
Although not likely, just a heads up that:
If C:\ had a file named Windows with no extension (thus it could not also
have a directory named windows), this would return that the Subdir was
found. You need to add a check that the found "file's" attributes match
vbDirectory. See the sample for the Dir command in help.
 
Tom,

Yes you're quite right...

Here's the ammended code:

Sub test()
Const cDir = "C:\", cSubDir = "WINDOWS"

Dim strTemp As String

strTemp = Dir(cDir, vbDirectory)
Do Until strTemp = ""
If LCase(strTemp) = LCase(cSubDir) Then
If (GetAttr(cDir & Application.PathSeparator & strTemp) And
vbDirectory) = vbDirectory Then Exit Do
End If
strTemp = Dir
Loop
If LCase(strTemp) = LCase(cSubDir) Then
MsgBox "SubDir Found"
Else
MsgBox "SubDir Not Found"
End If
End Sub
 
Thanks! I will give it a try
-----Original Message-----
Tom,

Yes you're quite right...

Here's the ammended code:

Sub test()
Const cDir = "C:\", cSubDir = "WINDOWS"

Dim strTemp As String

strTemp = Dir(cDir, vbDirectory)
Do Until strTemp = ""
If LCase(strTemp) = LCase(cSubDir) Then
If (GetAttr(cDir & Application.PathSeparator & strTemp) And
vbDirectory) = vbDirectory Then Exit Do
End If
strTemp = Dir
Loop
If LCase(strTemp) = LCase(cSubDir) Then
MsgBox "SubDir Found"
Else
MsgBox "SubDir Not Found"
End If
End Sub



--
Rob van Gelder - http://www.vangelder.co.nz/excel





.
 
Okay, I had a chance to look at the program but I don’t
get what it’s trying to do. especially the “strTemp = Dir
(cDir, vbDirectory)”. When I run it the
strTemp= “adobeweb.log”? I guess I am missing something.
Could the program be simplified to (my level) where I
input a directory like “C:\Documents and Settings\” then
the program would list (or output to a file) the
subdirectories?

thanks!
 
Back
Top