Using the right special characters

by ceem at 2012-10-04 04:27:18

Hey guys

I have a problem I couldn’t figure out by myself:
foreach ($file in $trkfiles){
copy-item $trkfolder$file “Y:\Logfiles$hname_$file”

For some the file won’t be renamed during the copy because of the “". If I’m using “-” everything works as it should.
Any ideas how I can rename the file with an "
” in it?

by mjolinor at 2012-10-04 06:25:28
by poshoholic at 2012-10-04 06:56:08
Mjolinor is right. When you use a variable name in a string, underscores are recognized as part of the variable name. You can explicitly tell PowerShell what the variable names are either by using subexpressions or by using curly braces around the variable names. Mjolinor’s example should work, as should this: