File Or Folder? Find Out!

by Jul 30, 2009

Test-Path can check whether a file or folder exists, but this does not tell you whether the path specified was actually a file or a folder. If you'd like to check whether the folder c:test exists, use this:

Test-Path c:test -pathtype container

If c:test was a file (without extension), Test-Path would still return false because with the -pathtype parameter, you explicitly looked for folders. Likewise, if you want to explicitly check for files, use the parameter -pathtype leaf.