VB 如何实现批量改名?

来源:百度知道 编辑:UC知道 时间:2024/05/05 09:32:08
我想把下面所示的下划线之前的数字改为三位数,如:

1_2.txt => 001_2.txt
3_5.txt => 003_5.txt
12_2.txt => 012_2.txt
14_2.txt => 014_2.txt

请问在 VB 中如何实现?

烦请高手指点,谢谢啦!

'窗体上,加入一个filelistbox控件
Private Sub Command1_Click()
File1.Path = "E:\name" '你的文件所在目录

For I = 0 To File1.ListCount - 1
pos = InStr(File1.List(I), "_")
If pos > 0 Then
shu = Left(File1.List(I), pos - 1)
If IsNumeric(shu) Then
newname = Format(shu, "000") & "_" & Right(File1.List(I), Len(File1.List(I)) - pos)
Name File1.Path & "\" & File1.List(I) As File1.Path & "\" & newname
End If
End If
Next
End Sub