่ชญ่€…ใงใ™ ่ชญ่€…ใ‚’ใ‚„ใ‚ใ‚‹ ่ชญ่€…ใซใชใ‚‹ ่ชญ่€…ใซใชใ‚‹

FileSystemObject ใ•ใ‚“ใŒ้…ใ„

Excel VBA

ๅ‰ใซ VBA ใง FileSystemObject ใ‚’ไฝฟใฃใŸๅ†ๅธฐ็š„ใชใƒ•ใ‚กใ‚คใƒซๆคœ็ดขใ‚’ใ—ใŸๆฐ—ใŒใ™ใ‚‹ใ‘ใฉใ€ๅฝ“ๆ™‚ใฎ่จ˜ๆ†ถใงใƒใƒƒใƒˆใƒฏใƒผใ‚ฏใƒ‰ใƒฉใ‚คใƒ–ใซๅฏพใ—ใฆใƒ•ใ‚กใ‚คใƒซๆคœ็ดขใ‚’่กŒใ†ใ‚ณใƒผใƒ‰ใ‚’ๆ›ธใ„ใŸใ‚‰่ถ…็ตถ้…ใ„ใ€‚ใƒžใ‚ธใงใ€Œใ“ใ‚“ใชใ‚“ไฝฟใฃใฆใ‚‰ใ‚Œใพใ›ใ‚“ใ‚๏ผใ€ใƒฌใƒ™ใƒซใ€‚

ใตใจใ€ๆ€ใ„ๅ‡บใ—ใฆ Dir ้–ขๆ•ฐไฝฟใฃใฆใฟใŸใ‚‰ใ‚ใกใ‚ƒใ‚ใกใ‚ƒๆ—ฉใ„ใ€‚ใฉใ‚Œใใ‚‰ใ„ๆ—ฉใ„ใ‹ใฃใฆใ„ใ†ใจ5ๅˆ†ใ‹ใ‹ใ‚‹ใ‚‚ใฎใŒ10็ง’ใง็ต‚ใ‚ใ‚‹ใƒฌใƒ™ใƒซใ€‚FileSystemObject ใฏ .SubFolders ใƒกใ‚ฝใƒƒใƒ‰ใ‚‚ .Files ใƒกใ‚ฝใƒƒใƒ‰ใ‚‚้…ใ„ใ€‚

ใจใ‚Šใ‚ใˆใš Collection ใฎๅ…ˆ้ ญใซ่ตท็‚นใจใชใ‚‹ใƒ•ใ‚ฉใƒซใƒ€ใ‚’็ชใฃ่พผใ‚“ใงใ€ใใ“ใ‹ใ‚‰ๅ…จใ‚ตใƒ–ใƒ•ใ‚ฉใƒซใƒ€ใ‚’ๅ†่ตทๆคœ็ดขใ€‚ใใ‚Œใ‹ใ‚‰ใ‚ตใƒ–ใƒ•ใ‚ฉใƒซใƒ€ใ‚’ใƒซใƒผใƒ—ใงๅ›žใ—ใฆใƒ•ใ‚กใ‚คใƒซๆคœ็ดขใ€‚ใ‚ณใƒžใƒณใƒ‰ใƒ—ใƒญใƒณใƒ—ใƒˆใ ใจ dir /s /a-d ใ ใ‘ใงๅ‡บๆฅใ‚‹ใ‚“ใ ใ‘ใฉใชใโ€ฆใ€‚

Option Explicit

Sub macro()
    
    Dim dirstack As New Collection
    dirstack.Add "C:\Windows"
    
    Dim i As Long
    i = 1
    Dim strName As String
    Do
        strName = Dir(dirstack(i) & "\", vbDirectory)
        Do While strName <> ""
            If (GetAttr(dirstack(i) & "\" & strName) And vbDirectory) = vbDirectory _
               And strName <> "." _
               And strName <> ".." _
            Then
                dirstack.Add dirstack(i) & "\" & strName
            End If
            strName = Dir()
        Loop
        i = i + 1
        If i > dirstack.Count Then
            Exit Do
        End If
    Loop
    
    i = i + 1
    Dim f as Variant
    For Each f in dirstack
        strName = Dir(f & "\" & "*.log")
        Do While strName <> ""
            Cells(i, 1) = f & "\" & strName
            strName = Dir()
            i = i + 1
        Loop
    Next f
    
    Columns.Sort _
        Key1:=Columns(1), _
        Order1:=xlAscending, _
        Header:=xlGuess, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom
    
    Columns.AutoFit
    
End Sub

Dir ้–ขๆ•ฐใฏใƒ•ใ‚กใ‚คใƒซๅ้ †ใซๅ‡ฆ็†ใ—ใฆใใ‚Œใชใ„ใฎใŒๆฌ ็‚นใ ใ‘ใฉ .Sort ใƒกใ‚ฝใƒƒใƒ‰ใŒใใ“ใใ“้€Ÿใ„ใฎใงใ“ใ‚Œใฏใชใ‚“ใจใ‹ใชใ‚Šใใ†ใ€‚