[MSH] get-childitem needs a item type switch

Discussion in 'Scripting' started by Keith Hill, Nov 2, 2005.

  1. Keith Hill

    Keith Hill Guest

    I have a handy alias set up in doskey that maps "dird" to "dir /AD $*" which
    lists just directories. I can't seem to find a straight forward way to do
    this with get-childitem. It would be nice if get-childitem had a switch
    called -ItemType that allowed you to specify "Leaf", "Container" or
    "AllTypes" and would default to "AllTypes". Also, is there a way to make
    get-childitem list directories first?
    Keith Hill, Nov 2, 2005
    1. Advertisements

  2. function dird { get-childitem $args | where-object { $_.MshIsContainer } }

    We have been trying to keep cmdlets small and composable rather than
    creating large commands. This allows the user to decide what they need to
    do and gives them the flexibility to do that. If we tried to put all the
    features in a single command then it would fall short in some areas and not
    provide a decent experience to get what the user really wants.

    That being said, we have talked about expanding the filter capability for
    the FileSystem provider to include the type and attributes of the items it
    returns. We'll be looking at this closer for v2.

    To sort them use sort-object:

    get-childitem | sort-object MshIsContainer #defaults to containers at
    the end

    get-childitem | sort-object MshIsContainer -descending # sorts containers
    to the top
    Jeff Jones [MSFT], Nov 2, 2005
    1. Advertisements

  3. Keith Hill

    Keith Hill Guest

    Thanks. This will work for now.
    Keith Hill, Nov 3, 2005
    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.