How do I create a folder?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried:

System.IO.File.Create("C:\FolderName")

It does not create a folder. Any ideas without using the File System Object?

Rachel
 
August 8, 2004

You have to create a IO.DirectoryInfo(path) with the path being the
parent of the folder you want. So if you wanted to create the folder:
"c:\program files\MyNewFolder", you would create a
DirectoryInfo("c:\program files") object. Then you call the
CreateSubDirectory(newfoldername) method of the DirectoryInfo object...

Private Sub Button1_Click(...)
Dim iDirectory as New System.IO.DirectoryInfo("c:\program files\")
iDirectory.CreateSubDirectory("MyNewFolder")
End Sub

This would then create the MyNewFolder in C:\Program Files\.
Have a nice day!


Joseph
 
With Deft Fingers said:
System.IO.File.Create("C:\FolderName")
It does not create a folder. Any ideas without using the File System Object?

Try this (or just take out what you want):

Dim TempDir As String
TempDir = "C:\FolderName"
If Directory.Exists(TempDir) Then
Exit Sub
Else : MkDir(TempDir)
End If


The MkDir is what you want.

Regards,

Bruce
 
Hi,

System.IO.Directory.CreateDirectory("C:\New Directory")



Ken

--------------------

I have tried:

System.IO.File.Create("C:\FolderName")

It does not create a folder. Any ideas without using the File System
Object?

Rachel
 
This works for me...

----------------------------------------------------

Option Explicit On
Option Strict On

'

Imports System.IO
Imports System.IO.Directory

'

Module PathModule

'

Friend Function CreatePath(ByVal thePath As String) As Boolean

Dim theDirectory As DirectoryInfo, _
thePathOrNot As Boolean

'

thePathOrNot = Exists(thePath)

If (Not (thePathOrNot)) Then

'

theDirectory = CreateDirectory(thePath)

With theDirectory

'

thePathOrNot = .Exists

End With

End If

'

Return (thePathOrNot)

End Function

End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top