PowerTip: Use PowerShell to Find File or Folder

Doctor Scripto

Summary: Learn how to use Windows PowerShell to find a file or a folder.

Hey, Scripting Guy! Question How can I use Windows PowerShell to determine if a variable contains a path that leads to a file or folder?

Hey, Scripting Guy! Answer Use the Test-Path cmdlet to test the path stored in the variable, and then specify the PathType parameter,
           for example:

PS C:\> $fso = "c:\fso"

PS C:\> $file = "C:\fso\backup.ps1"

PS C:\> Test-Path $fso -PathType leaf

False

PS C:\> Test-Path $file -PathType leaf

True

0 comments

Discussion is closed.

Feedback usabilla icon