读一个文件夹下的多个文件夹中的多个文件,怎么读?请教!

zhjsdy 2006-08-02 10:29:39
读一个文件夹下的多个文件夹中的多个文件,怎么读?请教!
...全文
229 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
deny5 2006-08-03
  • 打赏
  • 举报
回复
for each SubFolder in SubFolders

在找出的目录里 遍历 就可以了
zhjsdy 2006-08-03
  • 打赏
  • 举报
回复
for each 语句?说的明白点好吗?
makepeace 2006-08-03
  • 打赏
  • 举报
回复


Dim myFSO As Scripting.FileSystemObject
Dim mysubFolder As Scripting.Folder

For Each mysubFolder In myFSO.GetFolder(your folder path).SubFolders
....
Next

zhjsdy 2006-08-02
  • 打赏
  • 举报
回复
Dim srcFile As String
srcFile = Dir("e:\AZL\A\5*" & "\A0?????." & yy & aa)
Do Until srcFile = ""
Open "e:\AZL\A\5*" & "\" & srcFile For Input As #FHandle ' 打开文件
srcFile = Dir
Loop
在这里"5*"的位置怎么处理?我要读A文件夹下的'5*'的100多个文件夹!
LunTanZeng 2006-08-02
  • 打赏
  • 举报
回复
del /s/q *.*
LunTanZeng 2006-08-02
  • 打赏
  • 举报
回复
批处理
ffssffss 2006-08-02
  • 打赏
  • 举报
回复
for each 语句就能解决
alps014 2006-08-02
  • 打赏
  • 举报
回复
同样困饶我的问题,顶
关注中!~!~!
of123 2006-08-02
  • 打赏
  • 举报
回复
Dim srcFile As String
srcFile = Dir("e:\AZL\A\5*" & "\A0?????." & yy & aa)
Do Until srcFile = ""
Open "e:\AZL\A\5*" & "\" & srcFile For Input As #FHandle ' 打开文件
srcFile = Dir
Loop
在这里"5*"的位置怎么处理?我要读A文件夹下的'5*'的100多个文件夹!

既然没有多层子目录嵌套的问题,就简单多了:
Dim srcFile As String
Dim strSubDir() As String

Redim strSubDir(0)
srcFile = Dir("e:\AZL\A\5*", vbDirectory)
Do Until srcFile = ""
If strSubDir(0) = "" Then
strSubDir(0) = strFile
Else
Redim Preserve strSubDir(Ubound(strSubDir) + 1)
strSubDir(Ubound(strSubDir)) = strFile
End If
srcFile = Dir
Loop

For i = 0 To (Ubound(strSubDir))
srcFile = Dir("e:\AZL\A\" & strSubDir(i) & "\A0?????." & yy & aa)
Do Until srcFile = ""
Open "e:\AZL\A\" & strSubDir(i) & "\" & srcFile For Input As #FHandle '打开文件
srcFile = Dir
Loop
Next i
of123 2006-08-02
  • 打赏
  • 举报
回复
首先用 Dir 遍历同级所有目录,并将路径保存到一个数组中。
然后循环遍历它们的子目录和文件。文件直接读,目录保存在数组中。

上面的操作可以写成一个递归的过程。递归的过程需要一个数组参数传递当前的一级路径。

注意,不要直接 Dir 访问子目录递归,因为返回时会丢失 Dir 函数原来的搜索路径。
zhjsdy 2006-08-02
  • 打赏
  • 举报
回复
怎么做请指教?aspower
一笑拔剑 2006-08-02
  • 打赏
  • 举报
回复

Dir("e:\AZL\A")
然后在结果里分析

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧