Concatenate network path + variable

Powershell

Powershell Problem Overview


How can I concatenate this path with this variable?

$file = "My file 01.txt" #The file name contains spaces

$readfile = gc "\\server01\folder01\" + ($file) #It doesn't work

Thanks

Powershell Solutions


Solution 1 - Powershell

There are a couple of ways. The most simple:

$readfile = gc \\server01\folder01\$file

Your approach was close:

$readfile = gc ("\\server01\folder01\" + $file)

You can also use Join-Path e.g.:

$path = Join-Path \\server01\folder01 $file
$readfile = gc $path

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionexpirat001View Question on Stackoverflow
Solution 1 - PowershellKeith HillView Answer on Stackoverflow