我想在VB中編寫一個控制檯應用程序,它將允許我更改文件的名稱。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)
有什麼建議?
了'.ToString'對於'.Text'物業有點大材小用,因爲它單曲已經是一個字符串。 –