简体   繁体   English

使用字符串在指定位置创建文件夹

[英]Create folder in a specified location with strings

I´ve been working in a code that allow user to create a folder in a location specified with folder browser and name it with two text strings, but at this far, I've managed to create the folder on the default location.我一直在编写允许用户在文件夹浏览器指定的位置创建文件夹并用两个文本字符串命名的代码,但到目前为止,我已经设法在默认位置创建文件夹。

How can I set the location with the folder browser and have the new folder name with these texts as default.如何使用文件夹浏览器设置位置,并使用这些文本作为默认新文件夹名称。

The code this far is.到目前为止的代码是。

For create folder button:对于创建文件夹按钮:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim snombrecarpeta As String
        Dim sruta As Object
        snombrecarpeta = "QUO " & (quo.Text) & "_" & (proy.Text)
        sruta = ccliente()
        My.Computer.FileSystem.CreateDirectory(snombrecarpeta)
        MsgBox("Se ha creado la carpeta del proyecto")
    End Sub

For search folder button:对于搜索文件夹按钮:

Private Sub ccliente_Click(sender As Object, e As EventArgs) Handles ccliente.Click
        Dim ccliente = New FolderBrowserDialog()
        ccliente.SelectedPath = ("E:\Crear_carpetas\Crear_carpetas")
        If DialogResult.OK = ccliente.ShowDialog() Then
        End If  

Thanks in forward.谢谢转发。

And yes, I´m just starting in the vb world.是的,我刚刚开始涉足 vb 世界。

Creation of folder on Desktop, see Environment.GetFolderPath , and IO.Directory.CreateDirectory在桌面上创建文件夹,参见Environment.GetFolderPathIO.Directory.CreateDirectory

    Dim snombrecarpeta As String
    Dim sruta As Object
    snombrecarpeta = "QUO " & (quo.Text) & "_" & (proy.Text)
    sruta = ccliente()
    '
    ' e.g. create directory on Desktop
    '
    snombrecarpeta = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), snombrecarpeta)
    Try
        IO.Directory.CreateDirectory(snombrecarpeta)
        MessageBox.Show("Se ha creado la carpeta del proyecto")
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

edit:编辑:

    '
    ' https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.folderbrowserdialog?view=net-5.0
    '
    Dim path As String = ""
    Dim snombrecarpeta As String
    snombrecarpeta = String.Format("QUO{0}_{1}", (quo.Text), (proy.Text))
    Using fbd As New FolderBrowserDialog
        fbd.RootFolder = Environment.SpecialFolder.Desktop
        If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
            path = IO.Path.Combine(fbd.SelectedPath, snombrecarpeta)
        End If
    End Using

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM