Script Paradigm

ファイル一覧を取得

指定したフォルダのファイル一覧を取得します。
サブフォルダの中身も抽出します。

Option Explicit
MsgBox fnGetFilePathList("A:\Test")
Function fnGetFilePathList(ByVal strPath)
    fnGetFilePathList = fnPrivateGetFilePathList(strPath, strPath)
End Function
Private Function fnPrivateGetFilePathList(ByVal strParentPath, ByVal strCurrentPath)
    Dim fsoTemp
    Dim fldTemp
    Dim fleIdx
    Dim fldIdx
    Dim strFileName
    Dim strList
    
    '★初期化
    Set fsoTemp = CreateObject("Scripting.FileSystemObject")
    Set fldTemp = fsoTemp.GetFolder(strCurrentPath)
    
    '★ファイル一覧の表示
    For Each fleIdx In fldTemp.Files
        strFileName = fleIdx.Path
        strList = strList & strFileName & vbCrLf
    Next
    Set fleIdx = Nothing
    
    '★フォルダ一覧の表示
    For Each fldTemp In fldTemp.SubFolders
        strList = strList & fnPrivateGetFilePathList(strParentPath, fldTemp.Path)
    Next
    Set fldIdx = Nothing
    
    '★後始末
    Set fldTemp = Nothing
    Set fsoTemp = Nothing
    
    fnPrivateGetFilePathList = strList
End Function
Copyright © 2006 Hikijishi All Rights Reserved.
[] [wsh][0.00174307823181152]