Testing a path always returns False

Chucky

OS: Windows 10, Powershell: 5.1

I have the following Powershell Code

Test-Path -Path "$drive`\"

where $drive is a drive letter, I'm checking to see if a drive letter is mapped to a folder (be it network or local) and im always getting a value of False

Maximilian Burszley

You cannot neglect the colon (:) in your path:

Test-Path -Path C:\

Additionally, the escape (`) is entirely unnecessary here.

If you need to use a variable, you can use variable-delimiters (${}) in the string:

Test-Path -Path ${drive}:\

But if your goal is to check if a drive is mapped, you should use:

Get-PSDrive -Name <driveletter>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related