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

What the crap is this about?

I whipped up a fairly simple run-once and discard PowerShell script to iterate through all of the files in a list and make a simple change. The problem is every SPFile I get back is null. Every last one of them.

Now I understand that sometimes this is the case (like with forms: SPFile.Item == null and SPFolder.Item == null), but not on every last frigging file. I ran null checks up the hierarchy of my objects, and $folder is not null, but $file is. Seriously, what is wrong with this?

$web = Get-SPWeb $webUrl
$list = $web.GetList($listUrl)
foreach ($folder in $list.Folders)
{
    foreach ($file in $folder.Files)
    {
        // $file is null here
    }
}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Oh man, SPList.Folders actually returns an SPListItemCollection, not an SPFolderCollection...

However, SPList.RootFolder.SubFolders does return an SPFolderCollection...

share|improve this answer
1  
I was under the same impression once that SPList.Folders returns SPFOlderCollection. sharepoint.stackexchange.com/questions/49810/… –  Nadeem Yousuf Aug 15 '13 at 3:38
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.