我正在尝试在 VB 中编写一个控制台应用程序,它允许我更改文件的名称。
我到目前为止的代码是:
Public Class Form1
Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click
If txtpath.Text.Length <> 0 And txtName.Text.Length <> 0 Then
' Change "c:\test.txt" to the path and filename for the file that
' you want to rename.
' txtpath contains the full path for the file
' txtName contains the new name
My.Computer.FileSystem.RenameFile(txtpath.ToString, txtName.ToString)
Else
MessageBox.Show("Please Fill all Fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtpath.Clear()
txtName.Clear()
End Sub
End Class
但是当我尝试运行它时,我在这一行得到一个错误:
My.Computer.FileSystem.RenameFile(txtpath.ToString, txtName.ToString)
有什么建议么?