Summary: Learn how to use Windows PowerShell to determine if a path is to a file or a folder.
How can I use Windows PowerShell to determine if a path is to a file or a folder?
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