本文介绍了如何从visual basic中的文本框输入创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好,VB和学习新手,喜欢它:)。我想从文本框输入中在VB中创建一个文件夹,例如我有一个浏览...按钮,一个textbox1和一个创建文件夹按钮,我想创建一个文件夹,从浏览到用户想要创建文件夹的文件系统位置,所选位置应该复制到textbox1然后用户应该单击创建文件夹按钮,如果文件夹没有退出对话框应该说文件夹已成功创建,如果该文件夹存在应该说,该文件夹已存在。非常感谢所有帮助。谢谢。 这是我到目前为止所写的代码: Imports System.IO Public 类 Form1 Dim FolderName As 字符串 私有 功能 CreateFolder() FolderName = TextBox1.Text My.Computer.FileSystem.CreateDirectory( & FolderName& ) 如果 My.Computer.FileSystem.DirectoryExists( & FolderName& )= False 然后 投掷 新异常( 指定的路径不存在。) Else 如果 My.Computer.FileSystem.DirectoryExists( & FolderName& )然后 抛出 新异常( 无法创建文件夹,因为它已存在。) 结束 如果 结束 功能 私有 Sub FolderCreate() CreateFolder() 如果 不 My.Computer.FileSystem.DirectoryExists( & FolderName& )然后 投掷 新异常( 文件夹创建失败。) 结束 如果 结束 Sub 私有 Sub Button1_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 Button1 .Click FolderCreate() 结束 Sub 私有 Sub browse_Click(发件人 As Object ,e As Eve ntArgs)句柄 browse.Click 如果(FolderBrowserDialog1.ShowDialog()= Windows.Forms。 DialogResult.OK)然后 TextBox1.Text = FolderBrowserDialog1.SelectedPath 结束 如果 结束 Sub 结束 类 解决方案 我删除了文件夹检查并选择了更简单的代码:谢谢Sanisa 私有 Sub Browse_Click(发件人作为 对象, e As EventArgs)句柄 Browse.Click 如果(FolderBrowserDialog1.ShowDialog()= Windows.Forms.DialogResult.OK)然后 TextBox1.Text = FolderBrowserDialog1.SelectedPath 结束 如果 结束 Sub 这就是我想出来的: Dim txt As 字符串 txt = txtFolderPath.Text 如果 CheckBox1.CheckState = 1 然后 My.Computer.FileSystem.CreateDirectory( & txt& \ test) MessageBox.Show( 测试文件夹创建成功,单击确定) 结束 如果 Hi All, new to VB and learning, liking it :). I would like to create a folder in VB from a textbox input e.g. I have one "browse..." button, a "textbox1" and a "create folder" button, I want to create a folder from browsing to the file system location where the user would like to create the folder and the selected location should be copied to the textbox1 then the user should click the "create folder" button, if the folder doesn't exits a dialog should say the folder was successfully created if the folder exists it should say, the folder already exists. All help is very much appreciated. THANK you.This is the code that I'm trying to write so far:Imports System.IOPublic Class Form1Dim FolderName As StringPrivate Function CreateFolder()FolderName = TextBox1.TextMy.Computer.FileSystem.CreateDirectory("" & FolderName & "")If My.Computer.FileSystem.DirectoryExists("" & FolderName & "") = False ThenThrow New Exception("The specified path does not exist.")ElseIf My.Computer.FileSystem.DirectoryExists("" & FolderName & "") ThenThrow New Exception("Could not create the folder because it already exists.")End IfEnd FunctionPrivate Sub FolderCreate()CreateFolder()If Not My.Computer.FileSystem.DirectoryExists("" & FolderName & "") ThenThrow New Exception("The folder creation failed.")End IfEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickFolderCreate()End SubPrivate Sub browse_Click(sender As Object, e As EventArgs) Handles browse.ClickIf (FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) ThenTextBox1.Text = FolderBrowserDialog1.SelectedPathEnd IfEnd SubEnd Class 解决方案 I dropped the folder checking and went for the simpler code: Thanks SanisaPrivate 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 SubThis is what I've come up with:Dim txt As String txt = txtFolderPath.Text If CheckBox1.CheckState = 1 Then My.Computer.FileSystem.CreateDirectory("" & txt & "\test") MessageBox.Show("test folder created successfully, click OK") End If 这篇关于如何从visual basic中的文本框输入创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!