Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

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

share|improve this answer
add comment

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

SPFolder.Files.Count

is what you are looking for I believe.

share|improve this answer
add comment

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()
    }
}
share|improve this answer
add comment

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.

share|improve this answer
    
Note that SPFolder.ItemCount is not available in SP 2007. –  Dribbel Jun 25 '12 at 14:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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