variables in string name - trying to rename file

Welcome Forums General PowerShell Q&A variables in string name - trying to rename file

This topic contains 1 reply, has 2 voices, and was last updated by

11 months, 2 weeks ago.

  • Author
  • #104351

    Topics: 6
    Replies: 1
    Points: 1
    Rank: Member

    Hi there, Im having some difficulty in my renaming of a mp3 file.

    I want the renamed as the following style(theres 2 spaces before mark): {118-Cmin} Mark Alow – Black Light (Original Mix).mp3

    In my switch statement I have the following code. I'm finding it hard to use the "{" additionally with variables to get the rename the way I want it. Any hints would be greatly appreciated.

     'Minimal / Deep Tech' {
                          if (Test-Path "$destinationVar\Minimal") {
                          $newName = $bpm + $key + ' ' + $artist + $title 
                          Rename-Item -NewName { $ -Replace $newName 
                          Move-Item $file -destination "C:\Beatport Collection\Minimal" }
  • #104378

    Topics: 13
    Replies: 4872
    Points: 1,813
    Helping HandTeam Member
    Rank: Community Hero

    I'm not following the code at all, unfortunately.

    What I usually do is just include subexpressions within double quotes.

    $var = "$($this_variable).$($another)"

    The $() subexpression can contain whatever code you like, while outside the $() can contain whatever literal characters you want. It's much easier than concatenating strings.

    Hope that helps.

The topic ‘variables in string name - trying to rename file’ is closed to new replies.