Author Posts

March 13, 2017 at 9:12 pm


Bit new to powershell & trying to append a variable to windows path.
Say my variable is $filename (whose value is abc.txt) & i want to append it to my C drive like C:\$filename

Wondering what is the correct syntax for this ?

Thanks in advance for the help !

March 13, 2017 at 9:13 pm

Use Join-Path.

March 14, 2017 at 4:54 am

Join-Path, as Don mentions, can be very robust for using wildcards in paths to resolve multiple paths, but for what you are looking at, I find it simpler just to use the variable in a double-quoted string.

$filename = "abc.txt"

In the above $filename would be replaced with the value of the variable and the result would be "C:\abc.txt"