Hi,
Does anyone know any tactics or API that can create
multiple subdirectories ?
The current 'mkdir' command can only make 1 directory at a time.
I want to make the multiple subdirectories like C:\test1\test2\test3
Thanks in advance.
Printable View
Hi,
Does anyone know any tactics or API that can create
multiple subdirectories ?
The current 'mkdir' command can only make 1 directory at a time.
I want to make the multiple subdirectories like C:\test1\test2\test3
Thanks in advance.
You can do that via one API call:
VB Code:
Option Explicit Private Declare Function MakeSureDirectoryPathExists _ Lib "imagehlp.dll" (ByVal lpPath As String) As Long Private Sub Command1_Click() 'NOTE: make sure complete path ends with backslash MakeSureDirectoryPathExists "c:\dir1\subdir1\subdir2\" End Sub
@RhinoBull : What does the imagehlp.dll do ? Does it come with all versions of windows ? Even if I don't install MSPaint or similar tools ?
Edit: Nevermind. Just found it's documentation.
http://msdn.microsoft.com/library/de...pathexists.asp
You should really just check and create each directory in code
VB Code:
Dim fsObj as FileSystemObject Set fsObj = New FileSystemObject For i = 0 to UBound(Arr1) If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i)) For j = 0 to UBound(Arr2) If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i) & "\" & Arr2(j)) For k = 0 to UBound(Arr3) If Not fsObj.FolderExists(BaseDir & "\" & Arr1(i)) Then fsObj.CreateFolder(BaseDir & "\" & Arr1(i) & "\" & Arr2(j) & "\" & Arr3(k)) Next k Next j Next i Set fsObj = Nothing
Why the heck should we ??? You are creating brand NEW folder and all of its subfolders...Quote:
Originally Posted by umilmi81
Because:Quote:
Originally Posted by RhinoBull
A) It's not that hard
B) It does't require including any non-activeX Dll's
C) That's how you do it every other programming language
No, it's not but very redundant.Quote:
Originally Posted by umilmi81
It's a standard windows component since W2K and prior to that it was just another dll.Quote:
Originally Posted by umilmi81
Really? Never new that every other language would benefit from looping rather than single line call. :rolleyes:Quote:
Originally Posted by umilmi81
Name a language that automatically creates subdirectories for you. Perhaps the .NET file system object has an additional flag for this behavior. But I've never encountered one.Quote:
Originally Posted by RhinoBull
I'm just saying, it's a good practice to get into because it's just the way the paradigm works.
My friend - what are you talking about ??? You're writing your own program and there is an OS major component available for you so all you have to do is make a single call to one of its functions - that's all. If you wish not to than it's your decision and I wouldn't want to be part of it. What do you care how it is done in the C DLL - you should care more about performance and results and there is no way that VB6 can compete with C when it comes to string and/or directories structure parsing.