PowerShell v2 v3 Testing to see if a Folder or File Exists

These are mainly for me to jot down as reminders for myself. If I want to determine if file system object is a file (leaf) or folder (directory) I can use these two tests:

  1. Test folder: Test-Path -PathC: est -PathTypeContainer
  2. Test file: Test-Path -PathC: est -PathType Leaf 
$False, in these cases, can indicate two things:
  1. The item does not exist
  2. The item is not the PathType indicated
Be sure you know which you are testing for.

Related Posts by Categories

0 comments:

Post a Comment