WilliamW
WilliamW

Reputation: 468

A drive with the name C does not exist

I am trying to list the latest folder created on a powershell script:

$cmdOutput= dotnet nuget locals global-packages --list
$nugetPath = "$cmdOutput" -split 'info : global-packages: '
$orchFolder = "$nugetPath" + "myDllFolder"
echo $orchFolder # C:\Users\MyUser\.nuget\packages\myDllFolder
$latestFolder = Get-ChildItem -Directory $orchFolder

When using the above script, I am getting this error: Get-ChildItem : Cannot find drive. A drive with the name ' C' does not exist Even if my C drive exists.

I know there are questions related to this issue. But it did not help.

Note that when I replace this line:

It is working perfectly fine!

Which makes me think there is something wrong when I pass the variable directly. I tried to pass it through double quote, but still same error.

Any idea on what am I missing ?

Upvotes: 3

Views: 10731

Answers (1)

TheAshwaniK
TheAshwaniK

Reputation: 1826

Your problem is not on this line:

$latestFolder = Get-ChildItem -Directory $orchFolder

I believe the problem is in the way you are parsing the output returned by the previous commands.

$cmdOutput= dotnet nuget locals global-packages --list
$nugetPath = "$cmdOutput" -split 'info : global-packages: '
$orchFolder = "$nugetPath" + "myDllFolder"

Notice the extra space around the ' C' in your error message.

Upvotes: 2

Related Questions