|
-
Apr 5th, 2009, 04:28 AM
#1
Thread Starter
New Member
MkDir, maybe an old one
Hi,
I need to create a multilevel path like
"C:\Level1\Level2\Level3"
Public sub CreatePath()
MkDir "C:\level1\level2\level3"
End Sub
leads to an error 76 "path not found".
Public Sub createdir()
MkDir "C:\level11"
MkDir "C:\level11\level12"
MkDir "C:\level11\level12\level13"
End Sub
works fine but isn't very practical when the path has a greater changing numbers of levels.
Who knows how I can solve this problem on a simple way, suitable for a greater changing number of levels ??
jodo1955
-
Apr 5th, 2009, 04:52 AM
#2
Re: MkDir, maybe an old one
Try this...
I have not included error handling which I am sure you can take care of...
vb Code:
Private Sub Command1_Click() Dim StrFullPath As String, Myarray() As String '~~> Change this to the relevant path StrFullPath = "C:\Level1\Level2\Level3" Myarray = Split(StrFullPath, "\") MyNewPath = Myarray(0) For i = 1 To UBound(Myarray) '~~> Create Paths MkDir MyNewPath & "\" & Myarray(i) MyNewPath = MyNewPath & "\" & Myarray(i) Next i End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 5th, 2009, 05:02 AM
#3
Re: MkDir, maybe an old one
Use this API call:
Code:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" ( _
ByVal lpPath As String) As Long
Make sure lpPath ends with "\"
-
Apr 5th, 2009, 06:54 AM
#4
Re: MkDir, maybe an old one
 Originally Posted by anhn
Make sure lpPath ends with "\"
This is important...if you don't have the trailing "\" you will not receive an error or any other indication that it didn't work. However, without that "\" the folders will not be created.
-
Apr 5th, 2009, 07:02 AM
#5
Re: MkDir, maybe an old one
Example from APIGuide:
Code:
Private Declare Function SHCreateDirectoryEx Lib "shell32" Alias "SHCreateDirectoryExA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal psa As Any) As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'create the directory 'c:\test\dir\hello\something\apiguide\'
SHCreateDirectoryEx Me.hwnd, "c:\test\dir\hello\something\apiguide\", ByVal 0&
End Sub
-
Apr 5th, 2009, 08:11 AM
#6
Re: MkDir, maybe an old one
 Originally Posted by Hack
 Originally Posted by anhn
Make sure lpPath ends with "\"
This is important...if you don't have the trailing "\" you will not receive an error or any other indication that it didn't work. However, without that "\" the folders will not be created.
That's good to be mentioned.
I make a sub like this:
Code:
Sub MakeDeepDir(ByVal sPath As String)
MakeSureDirectoryPathExists sPath & "\"
End Sub
You can pass in sPath with or without trailing "\" because it is accepted if the path ends with "\\".
Unlike the classic MkDir, if the directory already existed, MakeSureDirectoryPathExists() will do nothing and not generate an error.
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
|