Skip to content

Empty folder size value should be set to zero #14449

@petrasteri

Description

@petrasteri

Steps to reproduce

We use the following instruction to calculate a folder size

gci c:\my_folder | measure Length -sum

However, if the folder is empty, this instruction returns an error. This happens in PowerShell 5 to PowerShell 7 (Win 10 to Windows Server 2016 to 2019). The error message is:

Measure-Object: Cannot process argument because the value of argument “Property” is not valid. Change the value of the “Property” argument and run the operation again.

Expected behavior

Returns 0. No error. Especially, no red error message on the screen.

Actual behavior

Big RED error message on the screen. Even though 0 is returned, but the error message is annoying.

Environment data

c:\my_folder is an empty folder

My opinion

Measure-Object’s behaviour is correct. So the culprit is the folder object returned by PowerShell. The size property of the folder object should be set to zero by default.

Of course, if other changes in PowerShell's internal working could lead to the disappearance of the error message, I'm happy with that too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions