open app.path & "\dir.txt" for output as #1
d=dir("d:\tmp\*.*")
do until d=""
print #1,d
d=dir
loop
close #1
以上是把D:\tmp文件夹中的所有文件名写到当前目录的dir.txt文件中
可以直接用SHELL+DOS命令
用记事本做一个1.bat文件,内容是:tree/f e:\小视频 >>d:\2.txt
然后在VB里:
Shell "e:\1.bat", vbHide
dim fs as filesystemobject
dim fsfolder as folder
dim fsfile as file
Dim xlApp As excel.Application
Dim xlBook As excel.Workbook
Dim xlSheet As excel.Worksheet
dim i as integer
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Set fs = New FileSystemObject
set fsfolder =fs.getFolder("文件夹路径")
i=1
for each fsfile in fsfolder.files
xlSheet.cells(i,1) = fsfile.name
i=i+1
next
xlApp.visible=true
set fs =nothing
set fsfolder=nothing
set fsfile=nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
我写过一个获得选定文件夹下文件目录并保存为TXT的程序,你需要可以发给你,留个邮箱