Public Class Form1 '将f:/123/文件下的txt文件改名(修改后的名字是0.txt,1.txt,2.txt.......) Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim files() As String '用于贮存文件名 Dim length As Integer = 0 'files数组长度 Dim fileName As String = Dir$("f:/123/*.txt") '得到第一个.txt文件的文件名 'Dim g As Graphics = Me.CreateGraphics Do While fileName <> "" 'g.DrawString(length,Font,Brushes.Red,length * 10,length * 10) ReDim Preserve files(length) files(length) = fileName length = files.Length fileName = Dir$() '得到下一个.txt文件的文件名 Loop For i = 0 To length - 1 Dim oldfileName As String = "f:/123/" + files(i) Dim newfileName As String = "f:/123/" + CStr(i) + ".txt" Rename(oldfileName,newfileName) '修改文件名 Next End Sub End Class