关于在VB中扫描文件的问题(100分)

dreamghost 2004-10-10 02:39:38
我现在需要扫描一个目录,这个目录包含若干级子目录,我需要得到所有这个目录及子目录中文件的绝对位置,如:C:|a|a|a.txt)需要怎么做?我是没思路了···大家帮帮忙···
...全文
138 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
evancss 2004-10-11
  • 打赏
  • 举报
回复
cmd.exe /c 本身就会在运行完毕后自动退出.
northwolves 2004-10-10
  • 打赏
  • 举报
回复
langkew(拉倒) 高!

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub Listfiles(ByVal mydir As String)
Dim x As String
Open "C:\test.bat" For Output As 1
Print #1, "cmd.exe/c dir " & mydir & "\*.* /s> c:\temp.txt"
Close 1
Shell "c:\test.bat"
Open "c:\temp.txt " For Binary As #1
x = Space(LOF(1))
Get #1, , x
Close #1
Debug.Print x
Kill "c:\temp.txt"
Kill "c:\test.bat"

End Sub

Private Sub Command1_Click()
Listfiles "c:\windows\system"
End Sub


如何强行退出DOS 界面?
jinta2001 2004-10-10
  • 打赏
  • 举报
回复
使用FSO对象,然后递归
tztz520 2004-10-10
  • 打赏
  • 举报
回复
northwolves(狼行天下)方法可行
evancss 2004-10-10
  • 打赏
  • 举报
回复
完整命令:
cmd.exe /c dir c:\ /s>c:\temp.txt
evancss 2004-10-10
  • 打赏
  • 举报
回复
提供思路一个:

用shellexecute执行:dir c:\ /s>c:\temp.txt

读c:\temp.txt分析文件及目录.
northwolves 2004-10-10
  • 打赏
  • 举报
回复
Sub Listfiles(ByVal mydir As String)
Dim n As Integer, dirlevel As Integer, fname As String, dirlist() As String, num As Long
num = 0
mydir = IIf(Right(mydir, 1) = "\", mydir, mydir & "\")
fname = Dir(mydir)
Do While fname <> ""
Debug.Print mydir & fname
num = num + 1
fname = Dir
Loop
fname = LCase(Dir(mydir, vbDirectory))
Do While fname <> ""
If fname <> "." And fname <> ".." Then
If GetAttr(mydir & fname) And vbDirectory Then
dirlevel = dirlevel + 1
ReDim Preserve dirlist(dirlevel)
dirlist(dirlevel) = mydir & fname
End If
End If
fname = Dir
DoEvents
Loop
For n = 1 To dirlevel
Listfiles dirlist(n) & "\"
Next
MsgBox "目录 " & mydir & " 共有 " & num & " 个文件"
End Sub

Private Sub Command1_Click()
Listfiles "c:\windows\system"
End Sub
starsoulxp 2004-10-10
  • 打赏
  • 举报
回复
up

7,763

社区成员

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

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