ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sub directories (https://www.excelbanter.com/excel-programming/289780-sub-directories.html)

mike

sub directories
 
Hello,

Is there a simple way to find if a sub directory exists or
not.

Thanks



Rob van Gelder[_4_]

sub directories
 
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

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


"Mike" wrote in message
...
Hello,

Is there a simple way to find if a sub directory exists or
not.

Thanks





Tom Ogilvy

sub directories
 
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.

--
Regards,
Tom Ogilvy


Rob van Gelder wrote in message
...
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

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


"Mike" wrote in message
...
Hello,

Is there a simple way to find if a sub directory exists or
not.

Thanks







Rob van Gelder[_4_]

sub directories
 
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


"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy


Rob van Gelder wrote in message
...
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

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


"Mike" wrote in message
...
Hello,

Is there a simple way to find if a sub directory exists or
not.

Thanks









mike

sub directories
 
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


"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy


Rob van Gelder

wrote in message
...
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

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


"Mike" wrote in

message
...
Hello,

Is there a simple way to find if a sub directory

exists or
not.

Thanks








.


Mike[_67_]

sub directories
 
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!
-----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


"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy


Rob van Gelder

wrote in message
...
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

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


"Mike" wrote in

message
...
Hello,

Is there a simple way to find if a sub directory

exists or
not.

Thanks








.



All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com