'--------------------------------------------------
'機能概要:指定フォルダ(サブフォルダ含む)内の全PDFファイル名とフルパスを取得
'--------------------------------------------------
Function fncGetPdfNames(strFolderPath As String) As String()
Dim fso As FileSystemObject
Dim folFolder As folder
Dim arrPdfNames() As String
Dim intIdx As Integer
Set fso = New FileSystemObject
Set folFolder = fso.GetFolder(strFolderPath)
intIdx = 0
Call prcGetPdfPaths(folFolder, arrPdfNames, intIdx)
fncGetPdfNames = arrPdfNames
End Function
'--------------------------------------------------
'機能概要:指定フォルダ内のPDFファイル名とフルパスを配列に格納(サブフォルダも再帰処理)
'--------------------------------------------------
Sub prcGetPdfPaths(folFolder As folder, _
arrNames() As String, _
ByRef intIdx As Integer)
Dim filFile As file
Dim folSubfolders As Folders
For Each filFile In folFolder.Files
If filFile.Name Like "*.pdf" Then
' PDF名前とフルパスの配列に追加
intIdx = intIdx + 1
ReDim Preserve arrNames(1, intIdx)
arrNames(0, intIdx) = filFile.Name ' ファイル名
arrNames(1, intIdx) = filFile.Path ' フルパス
End If
Next
For Each folSubfolders In folFolder.subfolders
Call prcGetPdfPaths(folSubfolders, arrNames, intIdx)
Next
End Sub
コメント