测试通过:Private Sub Command1_Click()Dim txtname As String
txtname = Dir(App.Path & "\*.txt") Do While txtname <> "" Debug.Print txtname txtname = Dir Loop
End Sub
Function GetFolder(FolderName) Dim FileManager As New FileSystemObject Dim Folder, Coll, Fii On Error Resume Next Set Foler = FileManager.GetFolder(FolderName) Set Coll = Foler.SubFolders For Each Fii In Coll '得到一层子文件夹 RenFile (Fii) '更改一层子目录文件 SubFolder = SubFolder + 1 GetFolder (Fii) '递归子文件夹 Next End Function Function RenFile(Fii) Dim FileManager As New FileSystemObject Dim File, FileName Dim NewName As String, KName Dim FColl Dim Fjj Dim ii As Long Dim jj As Long Dim KK As Long Dim WW On Error Resume Next Label5.Caption = "当前整理文件夹:" & Fii Frame1.Refresh Label5.Refresh DoEvents Set File = FileManager.GetFolder(Fii) Set FColl = File.Files jj = CLng(Combo1.Text) '取出设定长度 For Each Fjj In FColl '得到具体文件 NFileNum = NFileNum + 1 FileName = FileManager.GetFileName(Fjj) '得到文件名称 KName = FileManager.GetExtensionName(Fjj) If KName <> "" Then KName = "." & KName '扩展名 If Left(FileName, Len(Text1.Text)) <> Text1.Text Then KK = 0 '试验次数 Do Until Not FileManager.FileExists(Fii & "\" & Text1.Text & Format(ii, String(jj, "0")) & KName) KK = KK + 1 ii = ii + 1 If KK >= (10 ^ jj) Then jj = jj + 1 '自动将位数加一 End If Loop Fjj.Name = Text1.Text & Format(ii, String(jj, "0")) & KName ii = ii + 1 '将数字加一 FileNum = FileNum + 1 End If Next End Function '-------------------- 这是对文件和文件夹遍历的例子,需要的话,找我[email protected]
txtname = Dir(App.Path & "\*.txt")
Do While txtname <> ""
Debug.Print txtname
txtname = Dir
Loop
End Sub
Dim FileManager As New FileSystemObject
Dim Folder, Coll, Fii
On Error Resume Next
Set Foler = FileManager.GetFolder(FolderName)
Set Coll = Foler.SubFolders
For Each Fii In Coll '得到一层子文件夹
RenFile (Fii) '更改一层子目录文件
SubFolder = SubFolder + 1
GetFolder (Fii) '递归子文件夹
Next
End Function
Function RenFile(Fii)
Dim FileManager As New FileSystemObject
Dim File, FileName
Dim NewName As String, KName
Dim FColl
Dim Fjj
Dim ii As Long
Dim jj As Long
Dim KK As Long
Dim WW
On Error Resume Next
Label5.Caption = "当前整理文件夹:" & Fii
Frame1.Refresh
Label5.Refresh
DoEvents
Set File = FileManager.GetFolder(Fii)
Set FColl = File.Files
jj = CLng(Combo1.Text) '取出设定长度
For Each Fjj In FColl '得到具体文件
NFileNum = NFileNum + 1
FileName = FileManager.GetFileName(Fjj) '得到文件名称
KName = FileManager.GetExtensionName(Fjj)
If KName <> "" Then KName = "." & KName '扩展名
If Left(FileName, Len(Text1.Text)) <> Text1.Text Then
KK = 0 '试验次数
Do Until Not FileManager.FileExists(Fii & "\" & Text1.Text & Format(ii, String(jj, "0")) & KName)
KK = KK + 1
ii = ii + 1
If KK >= (10 ^ jj) Then
jj = jj + 1 '自动将位数加一
End If
Loop
Fjj.Name = Text1.Text & Format(ii, String(jj, "0")) & KName
ii = ii + 1 '将数字加一
FileNum = FileNum + 1
End If
Next
End Function
'--------------------
这是对文件和文件夹遍历的例子,需要的话,找我[email protected]
是死循环呀
to gump2000(阿甘) ( ) 信誉:102 sorry,是我少写了一句