Er...heather, that's a .Net solution. Error7, you get that error if you try to make a directory that already exists, not because there's a rule against making a directory called "C:\data". See VbSun's post. I'm sure you can verify this for yourself.
Draugen, you can also use the FileSystemObject. There are lots of posts on this.
I did verify this before posting. On my office W2k machine, the directory definately didn't and still doesn't exist. However, I just tried it at home on XP and I created the directory from within VB.
Alan
[gray]Experience is something you don't get until just after you need it.[/gray]
Heather code is good. You can use the File System Object ato see if the directory does exist and then appropriate action of either creating or not re-creating the directory.
<On my office W2k machine, the directory definately didn't and still doesn't exist.
Ok, then there's a reason for it I didn't think of. Perhaps in your office your SE has disallowed the creation of that directory. Easy way to find that out is to try to create it from a command line: md c:\temp.
Thank you all,I read all of your comment, but desided on usig vbSun's solution - together with error7'saddition, so I could avoid a untimely crash of the program. I also checked out BobRodesFileSystemObjects, but didn't find anything pertaning to the project I am working on, But some that I can use on future projects.
Again Thanks. The stars go to vbSun, and error7 for providing me with a working solution for my dilemma, and to BobRodes for providing me with future solution to future projects.
>>Heather code is good
Just to be clear, this is the VB 5 & 6 forum. That code will not work in VB 5 or 6. Just want to make that distinction for anyone else who wanders into this thread and tries to use that code in VB6.
> ... checked out BobRodes FileSystemObjects, but didn't find anything pertaning to the project ...
On Error Resume Next
CreateObject("scripting.filesystemobject").CreateFolder "C:\Data\MyDirectory"
Additionally there's a pretty similar function in the Microsoft Shell Controls And Automation library, the main difference really being that it doesn't require the exception handling
Dim myShell As Object
Set myShell = CreateObject("Shell.Application")
myShell.NameSpace("c:\").NewFolder "C:\Data\MyDirectory"
And then there's an API call which will create intermediate folders for you if they are missing (and again doesn't require the exception handling):
Private Declare Function SHCreateDirectoryEx Lib "shell32" Alias "SHCreateDirectoryExA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal psa As Any) As Long
Private Sub Command1_Click()
SHCreateDirectoryEx Me.hwnd, "C:\fso\data\example", ByVal 0&
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.