指定目录查找文件,文件夹
指定目录查找文件,文件夹 问题点数:10、回复次数:2Top
1 楼_1_(该用户已封杀)回复于 2002-05-10 09:08:01 得分 0
dir()Top
2 楼lovingkiss(桃花影落飞神贱,碧海潮生<吹>玉箫 坦白从良 抗拒强奸)回复于 2002-05-10 09:15:46 得分 10
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
'--------------------
这是对文件和文件夹遍历的例子,需要的话,找我loving-kiss@sohu.com
Top




