|
-
Aug 19th, 2002, 03:50 AM
#1
Thread Starter
Frenzied Member
MkDir Command - how to use with the filename
I need to use the MkDir Command when the string contains the required directory to be made and the filename.
e.g. I want to create a directory 'Directory1'
Code:
Dim fileLocation as String
fileLocation = "C:\Root\Directory1\file1.txt"
MkDir fileLocation
But I keep getting a Run-time error '76' Path not found. I know this is because I have the filename included in the string. How can I include the filename in the string without running into error?
Note: The file doesn't have to be created just the directory
-
Aug 19th, 2002, 03:57 AM
#2
Retired VBF Adm1nistrator
VB Code:
Private Sub someSub()
Dim fileLocation as String
fileLocation = "C:\Root\Directory1\file1.txt"
MkDir returnPathOfFile(fileLocation)
End Sub
Private Function returnPathOfFile(ByVal strFile As String) As String
returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
End Function
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 19th, 2002, 04:07 AM
#3
PowerPoster
Jamie is always drunk and so I think he misunderstood your question 
You need to Make the directory first and then create files within it. If u want the text in a textbox to be the name of a file or directory just put it outside of the quotes... eg fileLocation = "C:\Root\Directory1\" & text1.text
-
Aug 19th, 2002, 04:10 AM
#4
Retired VBF Adm1nistrator
Re: MkDir Command - how to use with the filename
Originally posted by mel_flynn
I want to create a directory 'Directory1'
Note: The file doesn't have to be created just the directory
:p
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 19th, 2002, 04:15 AM
#5
Thread Starter
Frenzied Member
Good Stuff! Thanks
Now, say I want to make multiple directories in the one statement i.e. Directory1 and Directory 2 :
Code:
Private Sub someSub()
Dim fileLocation as String
fileLocation = "C:\Root\Directory1\Directory2\file1.txt"
MkDir returnPathOfFile(FileLocation)
End Sub
Private Function returnPathOfFile(ByVal strFile As String) As String
returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
End Function
I keep getting path not found with MkDir returnPathOfFile(FileLocation). I know this is because both directories don't exist ... so how can I make both??
-
Aug 19th, 2002, 04:25 AM
#6
Retired VBF Adm1nistrator
You have to make one at a time afaik
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 19th, 2002, 06:25 AM
#7
Frenzied Member
As plenderj mentioned, you may have to write your own function for creating a nested directory structure. The one I used earlier is available at http://209.120.143.185/showthread.ph...hreadid=186500
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|