FG
💻 Software

PowerShell File Count Behaviour

Fresh5 days ago
Mar 15, 20264254 views
Confidence Score0%
0%

Problem

I'm new to PowerShell and have a question on the following behaviour. I'm trying to count the number of files in a directory of a certain type. If there are some, I will then copy them elsewhere. Here's the output of my test folder; the code is modified from MSDN examples I found: All well and good…

Error Output

[PS]> Get-ChildItem c:\pstdump

Directory: C:\pstdump

Mode                LastWriteTime     Length Name
----                -------------     ------…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: PowerShell File Count Behaviour

Low Risk

Call it a quirk or a feature, but this has to do with how PowerShell deals with lists that are only 1 in length. It "flattens" them so that it is no longer a list, but a single FileInfo object. Since the FileInfo object doesn't have a Count property…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment