dim s() as string
d=dir("d:\*.doc")
do until d=""
s=split(d,".")
s(ubound(s)-1)=s(ubound(s)-1) & "B"
name "d:\" & d as "d:\" & join(s,".")
d=dir
loop
msgbox "批量修改文件名完毕!"
列表框 List1
文本框 TxtFilePath
文本框 TxtFileName
按钮 CmdListFile
Private Sub CmdListFile_Click()
AutoListfiles TxtFilePath.txt, TxtFileName.Text
End Sub
'列出某个目录下所有指定类型文件(包含子目录)
'sDirName 目录名
'FileFilter 文件扩展名
'找到文件返回TRUE,一个也没找到则返回FALSE
Public Function AutoListfiles(ByVal sDirName As String, ByVal FileFilter As String) _
As Boolean
Dim sName As String
Dim sFile As String
Dim sExt As String
Dim sDirList() As String
Dim iDirNum As Integer
Dim i As Integer
On Error GoTo RF_ERROR
If Right$(sDirName, 1) <> "\ " Then sDirName = sDirName + "\ "
sFile = Dir(sDirName + FileFilter, vbNormal + vbArchive + vbHidden)
Do While Len(sFile) > 0
sFile = UCase(Trim(sFile))
'找到文件,在这里做你想做的
List1.AddItem sFile
sFile = Dir
Loop
iDirNum = 0
sName = Dir(sDirName + "*.* ", vbDirectory + vbNormal)
Do While Len(sName) > 0
If sName <> ". " And sName <> ".. " Then
iDirNum = iDirNum + 1
ReDim Preserve sDirList(1 To iDirNum)
sDirList(iDirNum) = sDirName + sName + "\ "
End If
sName = Dir
Loop
For i = 1 To iDirNum '递归调用
AutoListfiles sDirList(i), FileFilter
Next i
AutoListfiles = True
Exit Function
RF_ERROR:
MsgBox Err.Description, vbCritical, " "
AutoListfiles = False
End Function
后面的就很简单了。