Recursively count files in subfolders

后端 未结 6 1852
耶瑟儿~
耶瑟儿~ 2020-12-29 10:08

I am trying to count the files in all subfolders in a directory and display them in a list.

For instance the following dirtree:

TEST
    /VOL01
              


        
6条回答
  •  梦毁少年i
    2020-12-29 10:24

    My version - slightly cleaner and dumps content to a file

    Original - Recursively count files in subfolders

    Second Component - Count items in a folder with PowerShell

    $FOLDER_ROOT = "F:\"
    $OUTPUT_LOCATION = "F:DLS\OUT.txt"
    Function DirX($directory)
    {
        Remove-Item $OUTPUT_LOCATION
    
        foreach ($singleDirectory in (Get-ChildItem $directory -Recurse -Directory))
        {
            $count = Get-ChildItem $singleDirectory.FullName -File | Measure-Object | %{$_.Count}
            $summary = $singleDirectory.FullName+"    "+$count+"    "+$singleDirectory.LastAccessTime
            Add-Content $OUTPUT_LOCATION $summary
        }
    }
    DirX($FOLDER_ROOT)
    

提交回复
热议问题