PowerTip: Using PowerShell to Determine if Path Is to File or Folder

Summary: Learn how to use Windows PowerShell to determine if a path is to a file or a folder.

Hey, Scripting Guy! Question How can I use Windows PowerShell to determine if a path is to a file or a folder?

Hey, Scripting Guy! Answer Use the Get-Item cmdlet to get the object represented by the path. Then use the –Is operator to see if the
           object is a [system.io.directoryinfo] object or a [system.io.fileinfo] object. Here is an example:

PS C:\> (Get-Item c:\fso) -is [System.IO.DirectoryInfo]

True

PS C:\> (Get-Item C:\fso\csidl.txt) -is [System.IO.DirectoryInfo]

False