Share via


Method invocation failed because [System.IO.FileInfo] doesn't contain a method named 'GetFileSystemInfos'

Question

Wednesday, May 16, 2012 10:48 PM

Hi all

Why am I getting the error on the method: "GetFileSystemInfos().count"  below?

$vols = dir "c:\program files\microsoft services\media" #-include "*."
$Folders = 0
foreach ($vol in $vols)
{
    $Folders += $vol.GetFileSystemInfos().count
}

PS: I am not a PowerShell developer so any info here is well appreciated :)

Thank you

Max

All replies (2)

Thursday, May 17, 2012 2:16 AM âś…Answered

Hi,

We could run command:

dir "c:\program files\microsoft services\media" | get-member

and notice that GetFileSystemInfos() method is only for Directory, and File don't have this method.

So we should filter out those files included in the path by:

 

dir $path -Recurse | Where {$_.psIsContainer -eq $true}

Hope this helps.

Regards,

Yan Li

 

     

 

Yan Li

TechNet Community Support


Wednesday, May 16, 2012 10:58 PM

you make an assumption of the object type, you want to make sure its a directory only.. 

dir $path | where {$_.psiscontainer}

that will get only folders

Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.