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 |