473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create Directory

sueb
379 256MB
Wow, that was great! Now (and I guess I should have included this in my original question), can I create the "invalid" directory?

** Edit **
Split from Dynamic hyperlinks.
May 19 '10 #1

✓ answered by TheSmileyCoder

You can use mkdir (makedir) to make new directorys. Be advised though, that you can only create 1 dir at a time using that.For example:You can only create C:\test\test2 if c:\test allready exists. The usage goes:

Expand|Select|Wrap|Line Numbers
  1. mkDir "C:\Test"
Here is also a more advanced function that will loop through, and create the parent directories if they do not allready exist:
Expand|Select|Wrap|Line Numbers
  1. Public Function MakeDir(ByVal strPath As String) As Boolean
  2.     'creates a directory independent of whether the parent directory exists
  3.     'Code by TheSmileyOne
  4.     'Version 0.1
  5.     'Date 2010-05-19
  6.  
  7.     'Known issues
  8.     'No error handling for cases such as network drives, with restricted permissions to create folders.
  9.     'No input validation
  10.  
  11.  
  12.     On Error GoTo err_Handler
  13.  
  14.     'Check if rightmost char is a \
  15.         If Right(strPath, 1) = "\" Then
  16.             'Strip it
  17.             strPath = Left(strPath, Len(strPath) - 1)
  18.         End If
  19.  
  20.     'Check if each individual directory exists, and if not, create it
  21.         Dim strSplitPath() As String
  22.         ReDim strSplitPath(UBound(Split(strPath, "\")))
  23.         strSplitPath = Split(strPath, "\")
  24.         Dim intI As Integer
  25.         Dim strCombined As String
  26.  
  27.         For intI = 0 To UBound(strSplitPath)
  28.             If intI <> 0 Then strCombined = strCombined & "\"
  29.  
  30.             strCombined = strCombined & strSplitPath(intI)
  31.             If Dir(strCombined, vbDirectory) = "" Then
  32.                 MkDir strCombined
  33.             End If
  34.         Next
  35.  
  36.      'Succes
  37.          MakeDir = True
  38. Exit Function
  39.         MakeDir = False
  40.         MsgBox "Error " & Err.Number & " occured." & vbNewLine & Err.Description
  41.  
  42. End Function

6 3055
TheSmileyCoder
2,322 Expert Mod 2GB
You can use mkdir (makedir) to make new directorys. Be advised though, that you can only create 1 dir at a time using that.For example:You can only create C:\test\test2 if c:\test allready exists. The usage goes:

Expand|Select|Wrap|Line Numbers
  1. mkDir "C:\Test"
Here is also a more advanced function that will loop through, and create the parent directories if they do not allready exist:
Expand|Select|Wrap|Line Numbers
  1. Public Function MakeDir(ByVal strPath As String) As Boolean
  2.     'creates a directory independent of whether the parent directory exists
  3.     'Code by TheSmileyOne
  4.     'Version 0.1
  5.     'Date 2010-05-19
  6.  
  7.     'Known issues
  8.     'No error handling for cases such as network drives, with restricted permissions to create folders.
  9.     'No input validation
  10.  
  11.  
  12.     On Error GoTo err_Handler
  13.  
  14.     'Check if rightmost char is a \
  15.         If Right(strPath, 1) = "\" Then
  16.             'Strip it
  17.             strPath = Left(strPath, Len(strPath) - 1)
  18.         End If
  19.  
  20.     'Check if each individual directory exists, and if not, create it
  21.         Dim strSplitPath() As String
  22.         ReDim strSplitPath(UBound(Split(strPath, "\")))
  23.         strSplitPath = Split(strPath, "\")
  24.         Dim intI As Integer
  25.         Dim strCombined As String
  26.  
  27.         For intI = 0 To UBound(strSplitPath)
  28.             If intI <> 0 Then strCombined = strCombined & "\"
  29.  
  30.             strCombined = strCombined & strSplitPath(intI)
  31.             If Dir(strCombined, vbDirectory) = "" Then
  32.                 MkDir strCombined
  33.             End If
  34.         Next
  35.  
  36.      'Succes
  37.          MakeDir = True
  38. Exit Function
  39.         MakeDir = False
  40.         MsgBox "Error " & Err.Number & " occured." & vbNewLine & Err.Description
  41.  
  42. End Function
May 19 '10 #2
sueb
379 256MB
@TheSmileyOne
Smiley, this is wonderful! (In my code, I left in ALL the comment lines, including your authorship!) Now, I really do wish I'd asked this as a separate question so that I could mark this as "best" for this issue--thanks again!
May 19 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Don't worry about the Best Answer thing. This is my hobby, sorting small VBA challenges to me, is like I guess/imagine Sudoko is for other people.
May 19 '10 #4
NeoPa
32,556 Expert Mod 16PB
ADezii, being ADezii, asked if I would change the Best Answer (generous to a fault that boy) of the original thread. As this would not have been a best answer matching the question I could not do so (even at his request), but I was able to set it for this subsequent question as long as I split it into a separate thread (and I was happy to).
May 19 '10 #5
sueb
379 256MB
@NeoPa
I am so grateful to the contributors of this site--without you, this task would have taken so much longer and been so much more painful (not that I'm finished with it even yet!). But I am also so please to have found a community of such generosity and professionalism. It's been a long time since I've had the pleasure to bask in that kind of glow. I only hope that one day I'll be able to contribute something meaningful to a discussion.

Thanks again.
May 20 '10 #6
NeoPa
32,556 Expert Mod 16PB
Don't underestimate your beautifully expressed thanks Sue.

I know from my own experience how the boys will feel after working on this for you.

You take care, and come back and visit any time you fancy.
May 20 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
2
by: Christian Pické | last post by:
Hi, I tried following code, but I get an execption "URI formats not supported" Directory.CreateDirectory(@http://www.test.com/shop/images); The path is not located on my own computers, but...
2
by: Paul Bromley | last post by:
How can I create a directory within a shared ntwork directory?? sServerName - is the Server name "\Docs" - is the shared directory "\Others" - is the directory to create. The following...
4
by: tomek | last post by:
hi i'm desperate... i'm trying this for 2 days now... so if anyone can help - please. i have upload form in which users can choose TYPE of file they are uploading (graphic/text/music) - and...
5
by: AmitGujrathi | last post by:
Hi all,,, can anybody pls tell me how to create directory on web server using C#.Net windows application thanks in Advance Amit
4
by: Robert | last post by:
Greetings New to Visual Studio 2008. Always us VB6.0 SP5. I am trying to copy files from A to B. I select a directory, and copy files. Works ok, but it does not create the directory first. ...
4
by: kathy30 | last post by:
I'm storing files in SQL and retrieving them when needed to the user's C: Drive This is accessed on our Intranet site, the problem is the create directory and saving files happens on the Server...
6
by: coolestavi007 | last post by:
Hi, I have to create directories on the FTP server. I have tried directory.exists but it doesnt work.Any other way to create directory on the server.Please help me.
1
by: printline | last post by:
Hello all I have a php script that uploads a file from a form into a directory. The directory is automatically created through the script. But the upload file is not put in to the directory,...
4
Frinavale
by: Frinavale | last post by:
I am not the greatest system administrator and I am having some problems with my current setup which has crippled my ability to continue my current Joomla project that I'm working on. I cannot...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.