Using the right special characters

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5167

    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?

    Thanks

    by mjolinor at 2012-10-04 06:25:28

    Try:
    "Y:\Logfiles\$($hname)_$($file)"

    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:
    "Y]

You must be logged in to reply to this topic.