PDA

View Full Version : Solved: MkDir advice.....please!!!



sconly
05-21-2010, 02:37 AM
I am trying to make a folder/directory structure with MkDir.

The structure I'm trying to create is (for example) like this:
C:\Temp\Download\Misc

this is the code I'm using, but i get the error 'Path not found'
If Dir("C:\Temp\Download\Misc") = "" Then
MkDir "C:\Temp\Download\Misc"
End If


Is my code wrong or do i need to create one folder at a time?

Thanks.

GTO
05-21-2010, 03:52 AM
I am trying to make a folder/directory structure with MkDir.

The structure I'm trying to create is (for example) like this:
C:\Temp\Download\Misc

this is the code I'm using, but i get the error 'Path not found'
If Dir("C:\Temp\Download\Misc") = "" Then
MkDir "C:\Temp\Download\Misc"
End If


Is my code wrong or do i need to create one folder at a time?

Thanks.

If you are saying that \Temp and/or \Download are not yet existant, then you are correct. You can only create a folder at a time, as you need a path for the next sub-directory to harbor in.

mbarron
05-21-2010, 05:50 AM
You need to include the second argument to the Dir()
If Dir("C:\Temp\Download\Misc",vbDirectory) = "" Then
The first macro demonstrates what I mean. C:\Windows\System32 will exist on your computer (Windows XP at least) The fisrt msgbox will be blank the second will show system32 since the directory does exist

The second macro combines GTO's info as well as a completed method.


Sub system32()
MsgBox Dir("C:\Windows\system32")
MsgBox Dir("C:\Windows\system32", vbDirectory)

End Sub


Sub MakeDL_Misc()
If Dir("C:\Temp\Download\Misc", vbDirectory) = "" Then
If Dir("C:\Temp\Download", vbDirectory) = "" Then
MkDir "C:\Temp\Download\"
End If
MkDir "C:\Temp\Download\Misc"
End If
End Sub