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

4 Answers 4

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

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
    
Does the count includes checked-in and checked-out items/files? or only Check-in? –  Pranav-BitWiser May 19 at 10:30
    
@Pranav-BitWiser All files available. You have to add one more if-statement containing the argument for only checked-in/out files and a simple counter noOfItems++ inside that if-statement. –  Benny Skogberg May 19 at 10:43
    
which argument we need to pass to check for checked-in or checked-out files? –  Pranav-BitWiser May 19 at 10:45
    
@Pranav-BitWiser See: sharepoint.stackexchange.com/a/103622/6382 –  Benny Skogberg May 19 at 10:46

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

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

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.