[PS] Get-ChildItem and Get-ChildItem -Name have different ordering - Bug this?

Discussion in 'Scripting' started by Alex K. Angelopoulos [MVP], May 17, 2006.

  1. The command
    Get-ChildItem
    and
    Get-ChildItem -Name
    appear to use different ordering for output. Although we shouldn't make
    assumptions about enumeration order anyway, this looks like it could be
    confusing to entry-level users. Should I bug it?
     
    Alex K. Angelopoulos [MVP], May 17, 2006
    #1
    1. Advertisements

  2. Alex,

    The behaviour I see with

    get-childitem *.txt

    and

    get-childitem *.txt -Name

    is what I would expect to see according to the description of the Name
    parameter in the Help files. It says that when -Name is used only the
    name of the object is passed along the pipeline. So the default
    formatter only has the name to display when -Name is specified, if I
    understand things correctly.

    What I'm not immediately sure about is why I would really want a -Name
    parameter with get-childitem.

    Andrew Watt MVP
     
    Andrew Watt [MVP], May 17, 2006
    #2
    1. Advertisements

  3. Alex K. Angelopoulos [MVP]

    dreeschkind Guest

    Probably because it is faster than getting System.IO.FileSystemInfo objects?
    If you ony need the name for a certain task just use -Name to speed it up.
     
    dreeschkind, May 17, 2006
    #3
  4. The "name" of this parameter ought to be "-NameOnly" or something like that
    to indicate it is a switch. When I see -Name I feel like I need to provide
    an argument for the parameter.
     
    Keith Hill [MVP], May 18, 2006
    #4
  5. +1

    Andrew Watt MVP
     
    Andrew Watt [MVP], May 18, 2006
    #5
  6. +2

    I think, anyway. :)

    This is an odd situation. Name and Path are almost always input descriptors.
    In this case, it's used as an in-command output filter.
     
    Alex K. Angelopoulos [MVP], May 18, 2006
    #6
  7. Please file this on MS Connect, and vote if in agreement.

    The -Name parameter is there because it is often significantly more
    efficient to get the names of items, rather than just the items themselves.

    --
    Lee Holmes [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Lee Holmes [MSFT], May 19, 2006
    #7
  8. Lee - are you talking about bugging the original issue - the order in which
    output is displayed varying - or the question about the name of
    parameter -Name?

     
    Alex K. Angelopoulos [MVP], May 19, 2006
    #8
  9. Anything you would like to change :)

    --
    Lee Holmes [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.

     
    Lee Holmes [MSFT], May 19, 2006
    #9
  10. To give you an explanation about why they differ, though it is because of
    the way that we get directory listings.

    In essense Get-ChildItem (for the FileSystem) does:
    - [System.IO.Directory]::GetFiles("c:\temp")
    - [System.IO.Directory]::GetDirectories("c:\temp")

    When you specify the name parameter, we do:
    - [System.IO.Directory]::GetDirectories("c:\temp")
    - [System.IO.Directory]::GetFiles("c:\temp")

    --
    Lee Holmes [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.


     
    Lee Holmes [MSFT], May 19, 2006
    #10
  11. Ahh. Is there a specific intent behind the reversal?

     
    Alex K. Angelopoulos [MVP], May 19, 2006
    #11
  12. Andrew Watt [MVP], May 19, 2006
    #12
  13. That's what I'm wondering also.
     
    Keith Hill [MVP], May 19, 2006
    #13
  14. Not that I'm aware of.

    --
    Lee Holmes [MSFT]
    Windows PowerShell Development
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, and confers no rights.

     
    Lee Holmes [MSFT], May 22, 2006
    #14
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.