|
楼主 |
发表于 2011-8-25 20:58
|
显示全部楼层
回复 liuguansky 的帖子
能否也分享一下你如何继续查找 该文件夹内包含的子文件夹怎么继续处理呢???
下面是我从网搜索下来,自己修改了一下的..,经过测试是OK的,但是有一点没有通过,想将指定的目录修改成打开对话框CommonDialog1的目录,没有成功,不为何???
Private Sub Command3_Click() '这是 "提取整个文件夹的文件名" 按钮的代码
'引用FSO( "工程 "-> "引用 "-> Microsoft Scripting Runtime)
SearchFolder "e:\gongshitu" '想改成一个 CommonDialog1.initdir 测试了不能通过不知为何(当前前面加了一个CommonDialog控件)
'List1.Style = CheckBox VB中是不能在程序设置此属性的
MsgBox "所有的子文件夹搜索完毕" '此句如果放在下面的过程中会出现了2次以上的搜索完毕提示'
End Sub
Sub SearchFolder(ByVal Folder As String)
Dim Fso As New FileSystemObject
Dim objFile, objFolder
Dim n As Integer
Dim arr()
Set objFolder = Fso.GetFolder(Folder) 更改成了CommonDialog1.initdir 后,在这句报无效的路径 不知为何>???
For Each objFile In objFolder.Files
'if objFile.Path
WriteFile objFile.Path
n = n + 1
ReDim Preserve arr(1 To n)
If InStr(objFile.Path, ".jpg") > 0 Then
arr(n) = objFile.Path
If Mid(objFile.Path, InStrRev(objFile.Path, ".")) <> ".jpg" Then
MsgBox "里面包含非图片型文件,要注意"
Else
' instrrev(objfile.,".")
List1.AddItem objFile.Path '将文件名写到List1控件中去
End If
'n = InStr(1, Str, "\") 这些代码是用来从右边截取字符的代码,以便以后使用.
'While n
'Str = Right(Str, Len(Str) - n)
'n = InStr(1, Str, "\")
'Wend
End If
Next
'如果存在子文件夹的时候继续写'
For Each objFolder In objFolder.SubFolders
WriteFile objFolder.Path
If InStr(objFolder.Path, ".jpg") > 0 Then '查看是否包含了.jpg格式的文件
n = n + 1
ReDim Preserve arr(1 To n)
arr(n) = objFolder.Path
If Mid(objFolder.Path, InStrRev(objFolder.Path, ".")) <> ".jpg" Then '用了这层才能确保后缀名为.jpg格式'
MsgBox "里面包含非图片型文件,要注意"
Else
'instrrev(objfile.,".")
List1.AddItem objFolder.Path '将文件名写到List1控件中去
End If
End If
SearchFolder objFolder '递归遍历整颗树
Next
End Sub
|
|