4

Is there a way to get a count of the files under a folder in a SharePoint 2010 (enterprise) document library?

1

This may help - Gathering item count for all document libraries in a Site Collection (PowerShell script with some tweaking needed).

1
  • Blog has moved, but I believe this is an updated correct link. – apex Apr 23 '19 at 15:48
2

This works perfect for me $list.Items.Count in the following script:

$SPWebApp = Get-SPWebApplication "http://dev.company.com/"

foreach ($SPSite in $SPWebApp.Sites)
{
    if ($SPSite -ne $null)
    {
        foreach ($SPWeb in $SPSite.AllWebs)
        {
            foreach ($list in $SPWeb.Lists)
            {
                if($list.BaseType -eq "DocumentLibrary")
                {
                    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
                    Write-Host $ListURL
                    Write-Host "  No of item: " $list.Items.Count

                    if ($SPWeb -ne $null)
                    {
                        $SPWeb.Dispose()
                    }
                }
            }
        }
    }

    if ($SPSite -ne $null)
    {
        $SPSite.Dispose()
    }
}
0
1

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfilecollection.count.aspx

SPFolder.Files.Count

is what you are looking for I believe.

1

SPFolder.ItemCount will give you the number of items in the folder, but this is both files and subfolder and only direct children

If you only need the file count then the SPFolder.ItemCount - SPFolder.SubFolders.Count may be faster than SPFolder.Files.Count if there are a lot more files than folders and you're not going to use the SPFile objects for anything.

To get all files regardless of level you may loop through subfolders recursively.

1
  • Note that SPFolder.ItemCount is not available in SP 2007. – Dribbel Jun 25 '12 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.