$a = gci K:\test Directory must not have ...">

Length Property of DirectoryInfo Object

An empty directory "New folder" exists in K: \ test
>$a = gci K:\test


Directory must not have a Length property. Let me check:
[bool]($a.PSobject.Properties.Name -match "Length") False

Yes, it is not.
But:
>$a.Length 1

What does this mean?

+3


source to share


1 answer


This is a synthetic property that was added in V3 to prevent errors in scripts where an expression that would normally return an array could return a scalar and invoke array operations.



Now you can use Count or Length on any object, even if it didn't have this property. If the object did not have a Count or Length property, it will return 1 (or 0 for $ null). Objects that have Count or Length properties will continue to work as they always do.

+4


source







All Articles