回答編集履歴

1

コード修正

2022/05/16 07:53

投稿

hatena19
hatena19

スコア33763

test CHANGED
@@ -26,16 +26,19 @@
26
26
  Private Sub FileDisp(objFs As FileSystemObject, strPath As String, i As Long, shtFile As Worksheet)
27
27
  Dim objFld As Folder: Set objFld = objFs.GetFolder(strPath)
28
28
 
29
+ Dim aryFl()
30
+ If objFld.Files.Count > 0 Then
29
- Dim aryFl(): ReDim aryFl(1 To objFld.Files.Count, 1 To 4)
31
+ ReDim aryFl(1 To objFld.Files.Count, 1 To 4)
30
- Dim objFl As File, j As Long
32
+ Dim objFl As File, j As Long
31
- For Each objFl In objFld.Files
33
+ For Each objFl In objFld.Files
32
- j = j + 1
34
+ j = j + 1
33
- aryFl(j, 1) = objFs.GetBaseName(objFl.Path)
35
+ aryFl(j, 1) = objFs.GetBaseName(objFl.Path)
34
- aryFl(j, 2) = objFl.ParentFolder.Path
36
+ aryFl(j, 2) = objFl.ParentFolder.Path
35
- aryFl(j, 3) = Int(objFl.Size / 1024)
37
+ aryFl(j, 3) = Int(objFl.Size / 1024)
36
- aryFl(j, 4) = objFl.Type
38
+ aryFl(j, 4) = objFl.Type
37
- Next
39
+ Next
38
- shtFile.Cells(i, 2).Resize(j, 4).Value = aryFl
40
+ shtFile.Cells(i, 2).Resize(j, 4).Value = aryFl
41
+ End If
39
42
 
40
43
  For Each objFld In objFld.SubFolders
41
44
  FileDisp objFs, objFld.Path, i + j, shtFile