zoukankan      html  css  js  c++  java
  • File System Object(FSO对象)B

    一、实例FSO获取当前路径下的文件

     1 Sub Fsotest()
     2     Dim Fso As New FileSystemObject, Path As String, File
     3     Path = ThisWorkbook.Path & ""
     4     With Fso
     5         For Each File In .GetFolder(Path).Files '遍历路径下的所有Files
     6             If File.Name <> ThisWorkbook.Name Then
     7                 Debug.Print File.Name
     8             End If
     9         Next
    10     End With
    11 End Sub

     二、实例FSO遍历当前文件夹所有子文件夹

     1 Sub test()
     2     Call Getfd(ThisWorkbook.Path & "")
     3 End Sub
     4 
     5 Sub Getfd(ByVal Path As String)
     6     Dim Fso As New FileSystemObject
     7     Dim Folder As Variant
     8     For Each Folder In Fso.GetFolder(Path).SubFolders '遍历文件夹
     9         Debug.Print Folder
    10         Getfd (Folder) '递归遍历子文件夹
    11     Next
    12 End Sub

     三、实例FSO遍历当前文件夹及子文件夹下的所有Excel文件

     1 Sub Test()
     2     Call GetFile(ThisWorkbook.Path & "")
     3 End Sub
     4 
     5 Sub GetFile(ByVal Path As String)
     6     Dim Fso As New FileSystemObject
     7     Dim Folder As Variant, File As Variant
     8     
     9     For Each File In Fso.GetFolder(Path).Files '遍历 path路径下文件
    10         If File.Name Like "*.xls*" Then
    11             Debug.Print Path & File
    12         End If
    13     Next
    14     
    15     For Each Folder In Fso.GetFolder(Path).SubFolders '遍历文件夹
    16         'Debug.Print Folder
    17         GetFile (Folder) '递归遍历子文件夹
    18     Next
    19 End Sub
  • 相关阅读:
    ElasticSearch 2 (10)
    zookeeper 配置
    zookeeper
    ES 聚合函数
    win 7安装 linux
    Elasticsearch分布式搜索集群配置
    Elasticsearch 插件安装
    为Elasticsearch添加中文分词,对比分词器效果
    .net 4.0 网站发布(转)
    ssm 网页
  • 原文地址:https://www.cnblogs.com/Ionefox/p/10255637.html
Copyright © 2011-2022 走看看