|
楼主 |
发表于 2020-1-12 14:56
|
显示全部楼层
本帖最后由 青春の火焰 于 2020-1-12 19:09 编辑
Option Explicit
Sub test()
Dim f, pth, mark
pth = "d:\photo"
If Right(pth, 1) <> "\" Then pth = pth & "\"
If Dir(pth, vbDirectory) = vbNullString Then MsgBox pth: Exit Sub 'If Dir(全路径, vbDirectory) = vbNullString ,判断文件或文件夹是否存在,vbNullString是不存在
f = Dir(pth & "*.*")
mark = ".jpg"
On Error GoTo errmsg
Do While Len(f) > 0
If LCase(Right(f, Len(mark))) = LCase(mark) And InStr(f, "_") = 4 Then Name pth & f As pth & Mid(f, 5)
f = Dir
Loop
Exit Sub
errmsg:
MsgBox "文件无法改名(可能已打开):" & pth & f
End Sub
老师,看了你的代码,很有用,但有处看不明白,请教下您,谢谢
变量mark,怎么得出的他的值是".jpg"
|
|