我有一个vb应用程序,它可以复制文件夹及其正常运行的子文件夹。我的问题是它没有复制要复制的文件夹的正确文件夹名称。
就像我将文件夹复制到以下位置:C:\ Users \ Documents \ Sample_Folder 输出的复制文件夹名称将为“文档”。
C:\ Users \ Documents \ Sample_Folder \ Sample_Folder_2 输出的复制文件夹名称将为“ Sample_Folder”。
Private Sub btnCopy_Click(sender As Object, e As EventArgs) Handles btnCopy.Click
Dim SourcePath As String = txtBrowse.Text
Dim DestinationPath As String = "C:\Users\1000258123\Desktop\NEW"
Dim newDirectory As String =
System.IO.Path.Combine(DestinationPath,
Path.GetFileName(Path.GetDirectoryName(SourcePath)))
If Not (Directory.Exists(newDirectory)) Then
Directory.CreateDirectory(newDirectory)
End If
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(SourcePath, newDirectory)
MsgBox("Copy Successful")
End Sub