列出文件目录结构

以下代码可快速列出所有文件夹,子文件夹下文件

用tree /f显示为树形结构

    mypath = wsh.exec("cmd /c tree /f " & Chr(34) & mypath & Chr(34)).StdOut.ReadAll

    6cf86e7fbbc42d3dfde4c3337e3584a7cc8.jpg

用 dir显示为长文件名结构

mypath = wsh.exec("cmd /c dir /a /s /b /a-d " & Chr(34) & mypath & Chr(34)).StdOut.ReadAll

31192e210b9242f05f11cc3a7f140561610.jpg

'http://club.excelhome.net/thread-967698-2-1.html
Sub File_List()
    On Error GoTo 100
    Dim wsh As Object, mypath As String, ar, st$
    mypath = "C:\Users\zhengh\Documents\BARTEC"
    Set wsh = CreateObject("wscript.shell")
    mypath = wsh.exec("cmd /c tree /f " & Chr(34) & mypath & Chr(34)).StdOut.ReadAll
    mypath = Left(mypath, Len(mypath) - 1)
    ar = Split(mypath, vbCrLf)
    ar = Filter(ar, st)
    Set wsh = Nothing
    Cells.ClearContents
    Range("a1").Resize(UBound(ar) + 1) = Application.Transpose(ar)
100:
End Sub

 

转载于:https://my.oschina.net/tedzheng/blog/2988414

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值