Tip: You can test if a path is a file or a folder using Test-Path cmdlet:
1 2 3 4 5 6 |
# Check if file (works with files with and without extension) Test-Path -Path 'C:\Demo\FileWithExtension.txt' -PathType Leaf Test-Path -Path 'C:\Demo\FileWithoutExtension' -PathType Leaf # Check if folder Test-Path -Path 'C:\Demo' -PathType Container |
Pingback: Powershell Tip #117: Remove whitespaces from a string | Powershell Guru
Pingback: Powershell Tip #119: Increase the number of lines sent to pipeline with Get-Content | Powershell Guru