General discussion

Locked

VB Creating a New Folder

By True_Texan ·
I am creating a new folder using the following code mynewfolder = myFileSystem.CreateFolder(dirDirectory.Path + "\" + NewFolder) using an input box to get NewFolder. However, I get a run-time error #70 saying permission denied if I try and make a new folder under c Is there a way around this? Thank you.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

VB Creating a New Folder

by juanja In reply to VB Creating a New Folder

Try to access de file System Object by using this method:

Private Sub Command1_Click()
' Get instance of FileSystemObject.
Set fso = CreateObject("Scripting.FileSystemObject")

This method works for vbcript and Visual Basic.
Then, proceed tocreate the folder. Consider this: If you are in some folder other than root ( C ), the dir1.path method will return:

c:\bogus

but if you are in the root ( C ), it will return:

C:
Notice that in the first one you don't have the backslash (\) at the end. Therefore, you must check to see if you have it or not, and store the right path and name for the new folder in a variable (path_name):

' Create a new folder with the FileSystemObject object.

If Right(Dir1.Path, 1) = "\" Thenpath_name = Dir1.Path & Text1.Text
Else
path_name = Dir1.Path & "\" & Text1.Text
End If

fso.CreateFolder (path_name)
Set fso = Nothing
'To set the folder display to the new folder
Dir1.Path = path_name
Dir1.Refresh
End Sub

This will avoid any errors. Don't forget to check if the folder already exists, and rate my answer.

Collapse -

VB Creating a New Folder

by True_Texan In reply to VB Creating a New Folder

Poster rated this answer

Collapse -

VB Creating a New Folder

by Mohammad_M_Saggaf In reply to VB Creating a New Folder

VB support creating folders. Try this:

dim StrPath as string
StrPath= InputBox(Message, Title, "")
If StrPath <> "" Then MkDir StrPath

Where Message and Title are the message and title you want them to appare in the input box.

I hope it helped

Collapse -

VB Creating a New Folder

by True_Texan In reply to VB Creating a New Folder

Poster rated this answer

Collapse -

VB Creating a New Folder

by True_Texan In reply to VB Creating a New Folder

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums