|
▼にしもり さん:
いまさらですが、
> Sub FileSearch(Path As String, 貼付行 As Long)
> Dim Folder As Object
> Dim File As Object
>
> With CreateObject("Scripting.FileSystemObject")
> For Each Folder In .GetFolder(Path).SubFolders
>
> Call FileSearch(Folder.Path, 貼付行)
>
> For Each File In .GetFolder(Path).Files
> 貼付行 = 貼付行 + 1
> Cells(貼付行, 1).Value = File.Path
> Next File
>
> Next Folder
> End With
>
> End Sub
この処理順、おかしくないですか?
実行すると、
同じファイルが 何度も書き出されないですか?
先に 指定フォルダ内のファイルを書き出して、
それから サブフォルダを再帰で検索したほうがいいような気がします。
'↓ ★ 事前に Microsoft Scripting Runtime へ参照設定が必要です。
Sub Sample()
Dim Fso As Scripting.FileSystemObject
Dim oFolder As Scripting.Folder
Set Fso = New Scripting.FileSystemObject
Set oFolder = Fso.GetFolder("C:\_cosmos\Tr")
FileSearch2 oFolder, 0
End Sub
Private Sub FileSearch2(myFolder As Scripting.Folder, _
貼付行 As Long)
Dim oFolder As Scripting.Folder
Dim oFile As Scripting.File
Dim s As String
For Each oFile In myFolder.Files
貼付行 = 貼付行 + 1
Cells(貼付行, 1).Value = oFile.Path
Next
For Each oFolder In myFolder.SubFolders
FileSearch2 oFolder, 貼付行
Next
End Sub
|
|