Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default sub directories

Hello,

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

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default 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








.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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








.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating directories freekrill Excel Discussion (Misc queries) 1 July 25th 05 09:26 AM
Directories Jeff[_24_] Excel Programming 4 January 20th 04 09:26 AM
changing directories Andrea[_7_] Excel Programming 2 November 5th 03 09:22 PM
Searching directories... Keith Willshaw Excel Programming 0 August 1st 03 09:20 AM
Searching directories... Phobos Excel Programming 0 August 1st 03 12:03 AM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"