1

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
    }
}
3

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

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

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.