我製作搜索程序用於搜索計算機中的文件列表,然後將該文件複製到商店文件夾中。文件名可以是「* 11 * 2.txt」只要程序找到這個模式,它就應該複製到商店文件夾中。問題是,我不知道搜索前的文件的確切名稱,我不想重命名文件,我不知道如何保存文件。請幫助如何在VB中獲取文件的文件名?
我使用以下方法來查找文件,它不工作
Public Sub DirSearch(ByVal sDir As String, ByVal FileName As String)
Dim To_Path As String
To_Path = Form1.TextBox5.Text
For Each foundFile As String In My.Computer.FileSystem.GetFiles(sDir, FileIO.SearchOption.SearchAllSubDirectories, FileName)
Copy2Local(foundFile, To_Path)
Next
End Sub
這裏是Copy2Local的當前版本(注:這是不對的工作)
Public Sub Copy2Local(ByVal Copy_From_Path As String, ByVal Copy_To_Path As String)
' Specify the directories you want to manipulate.
Try
Dim fs As FileStream = File.Create(Copy_From_Path)
fs.Close()
' Copy the file.
File.Copy(Copy_From_Path, Copy_To_Path)
Catch
End Try
End Sub
@Heinzi感謝您的建議。 VB說它找不到Copy_To_Path。我將Copy_To_Path設置爲文件夾名稱,這是錯誤的。它應該是一個文件名。但是,如果我搜索「* ab * c.txt」,我不知道如何將其設置爲文件名(注意:我想保留程序搜索的內容,換句話說,如果結果是ab1c.txt,我想通過重命名將此文件複製到商店文件夾中)。謝謝 – Marco