「Excel VBA ディレクトリの再帰処理」の版間の差分
ナビゲーションに移動
検索に移動
(ページの作成:「==Excel VBA ディレクトリの再帰処理== [Excel VBA]{{category VBAソース片}} ===FileSystemObjec=== http://msdn.microsoft.com/ja-jp/library/cc392182.aspx…」) |
|||
| 1行目: | 1行目: | ||
==Excel VBA ディレクトリの再帰処理== | ==Excel VBA ディレクトリの再帰処理== | ||
| − | [Excel VBA]{{category VBAソース片}} | + | [[Excel VBA]]{{category VBAソース片}} |
===FileSystemObjec=== | ===FileSystemObjec=== | ||
2020年2月15日 (土) 08:02時点における版
Excel VBA ディレクトリの再帰処理
Excel VBAテンプレート:Category VBAソース片
FileSystemObjec
http://msdn.microsoft.com/ja-jp/library/cc392182.aspx
ディレクトリの再帰処理をDir関数を使って書こうと思ったら、困難そうなので、FileSystemObjectを使う。
Const FileAttrNormal = 0
Const FileAttrReadOnly = 1
Const FileAttrHidden = 2
Const FileAttrSystem = 4
Const FileAttrVolume = 8
Const FileAttrDirectory = 16
Const FileAttrArchive = 32
Const FileAttrAlias = 64
Const FileAttrCompressed = 128
Private fso As Object
Public Sub recursiveProc()
Dim d As String
Dim folder As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("c:\")
Call traverse(folder)
End Sub
Private Function traverse(path As Object) As Object
Dim sfs As Object
Dim sf As Object
Dim fs As Object
Dim f As Object
If path.Attributes And FileAttrDirectory Then
Debug.Print "DIR : " & path
Set sfs = path.subFolders
For Each sf In sfs
Call traverse(sf)
Next
Set fs = path.Files
For Each f In fs
Call traverse(f)
Next
End If
If path.Attributes And FileAttrArchive Then
Debug.Print "FILE : " & path
End If
End Function
© 2006 矢木浩人