Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
Is there a simple way to find if a sub directory exists or not. Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
creating directories | Excel Discussion (Misc queries) | |||
Directories | Excel Programming | |||
changing directories | Excel Programming | |||
Searching directories... | Excel Programming | |||
Searching directories... | Excel Programming |