調試時出現以下錯誤。如何在Visual Basic 2010中移動或替換文件或文件夾?
未處理的異常已經發生
無法完成操作,因爲文件已經在這條道路存在「C:\ 32位\ abc.dll」
我怎樣才能解決這個問題?
Imports System
Imports System.IO
Public Class Form1
Private Sub ReactorButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReactorButton1.Click
If ReactorComboBox1.SelectedItem = "Some Program" Then
My.Computer.Network.DownloadFile _
("http://somesite/test/abc.dll", _
"C:\32bit\abc.dll", True, 500)
System.IO.File.Move("C:\32bit\abc.dll" "C:\Program Files\Some Program\abc.dll")
My.Computer.Network.DownloadFile _
("http://www.somerandomsite/test1/abcd _
"C:\64bit\abcd.dll", True, 500)
System.IO.File.Move("C:\64bit\abcd.dll… "C:\Program File (x86)\Some Other Program\abcd.dll")
End If
End Sub
我也試過
Try
Catch ex As Exception
System.IO.File.Delete("C:\32bit\abc.dll")
End Try
Try
Catch ex As Exception
My.Computer.Network.DownloadFile _
("http://somesite.com/folder/32bit/abc.dll", _
"C:\32bit\abc.dll", True, 500)
End Try
System.IO.File.Copy("C:\32bit\abc.dll", "C:\Program Files (x86)\A Program\Sub Folder\abc.dll")
但我仍然得到同樣的未處理的異常錯誤。
你的移動方法看起來很奇怪。這兩個文件名之間不應該有逗號? (即System.IO.File.Move(「C:\ 32bit \ abc.dll」**,**「C:\ Program Files \ Some Program \ abc.dll」) –