【发布时间】:2015-05-07 15:40:10
【问题描述】:
我需要将使用 OpenFileDialog 选择的 mp3 文件复制到新目录。问题是文件夹内的所有文件都复制到新目录。我只想复制在该文件夹中选择的特定文件。请帮忙。
注意:打开mp3文件后,Textbox1会显示文件的源路径(sourcepath)。然后 Textbox2 将在点击保存按钮后显示新路径(destPath)。
Private Shared Sub CopyDirectory(ByVal sourcePath As String, ByVal destPath As String)
If Not Directory.Exists(destPath) Then
Directory.CreateDirectory(destPath)
End If
For Each file__1 As String In Directory.GetFiles(Path.GetDirectoryName(sourcePath))
Dim dest As String = Path.Combine(destPath, Path.GetFileName(file__1))
File.Copy(file__1, dest)
Next
For Each folder As String In Directory.GetDirectories(Path.GetDirectoryName(sourcePath))
Dim dest As String = Path.Combine(destPath, Path.GetFileName(folder))
CopyDirectory(folder, dest)
Next
End Sub
Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
Dim sourcepath As String = ""
Dim DestPath As String = "C:\Users\Big Boss Eis\Desktop\vb file maintenance\fileMaintenance with database\fileMaintenance"
sourcepath = TextBox1.Text
CopyDirectory(sourcepath, DestPath)
End Sub
Private Sub OpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFile.Click
If (OpenFileDialog1.ShowDialog = DialogResult.OK) Then
AxWindowsMediaPlayer1.URL() = OpenFileDialog1.FileName
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
【问题讨论】:
标签: vb.net openfiledialog