简体   繁体   中英

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.

Creation of folder on Desktop, see Environment.GetFolderPath , and IO.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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