Scripting Games–new Get-ChildItem parameters

One improvement that came with PowerShell v3 is the –File and –Directory parameters on Get-ChildItem

If I run this

Get-ChildItem -Path c:\mydata

I will get a mixture of directories and files

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
d—-        19/11/2012     20:19            Delivery
d—-        26/02/2013     19:24            Demo
d—-        05/05/2013     11:26            ScriptingGames 2013
d-r–        07/05/2013     18:17            SkyDrive
d—-        24/01/2013     20:08            Summit NA 2012
-a—        06/05/2013     15:26    1336320 2013May_ErrorHandling.doc

If I add the –Recurse parameter it gets worse – I know I’ve got a lot of files and directories in here.

In PowerShell v2 you could separate the directories and files by using PSISContainer

Get-ChildItem -Path c:\mydata | where {$_.PSIsContainer}
Get-ChildItem -Path c:\mydata | where {!$_.PSIsContainer}

will give you the directories only and files only respectively.

It gets easier in PowerShell v3

Get-ChildItem -Path c:\mydata -Directory
Get-ChildItem -Path c:\mydata –File

simple and obvious when you read it.

if you are using PowerShell v3 don’t forget these parameters

This entry was posted in PowerShell V3, Scripting Games. Bookmark the permalink.

3 Responses to Scripting Games–new Get-ChildItem parameters

  1. cavallogolooso says:

    how long will we have to wait until V3 requirements and conflicts will be solved?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s