【发布时间】:2014-10-17 10:53:05
【问题描述】:
我想从textbox 输入例如VB 创建一个文件夹我有一个“浏览”按钮、一个textbox1 和一个“创建文件夹”按钮,我想创建一个从浏览到用户想要创建文件夹的文件系统位置的文件夹,并且选择的位置应该被复制到textbox1 然后用户应该点击“创建文件夹”按钮;如果文件夹没有退出,对话框应该说文件夹已成功创建如果文件夹存在它应该说文件夹已经存在。
非常感谢所有帮助。谢谢。
这是我目前正在尝试编写的代码:
Imports System.IO
Public Class Form1
Dim FolderName As String
Private Function CreateFolder()
FolderName = TextBox1.Text
My.Computer.FileSystem.CreateDirectory("" & FolderName & "")
If My.Computer.FileSystem.DirectoryExists("" & FolderName & "") = False Then
Throw New Exception("The specified path does not exist.")
Else
If My.Computer.FileSystem.DirectoryExists("" & FolderName & "") Then
Throw New Exception("Could not create the folder because it already exists.")
End If
End Function
Private Sub FolderCreate()
CreateFolder()
If Not My.Computer.FileSystem.DirectoryExists("" & FolderName & "") Then
Throw New Exception("The folder creation failed.")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderCreate()
End Sub
Private Sub browse_Click(sender As Object, e As EventArgs) Handles browse.Click
If (FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
End Class
【问题讨论】:
标签: vb.net directory creation folderbrowserdialog