variables in string name - trying to rename file

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 5 days, 5 hours ago.

  • Author
    Posts
  • #104351

    squigee
    Participant

    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 { $_.name -Replace $newName 
                         
                         pause 
                           
                          Move-Item $file -destination "C:\Beatport Collection\Minimal" }
                     
                                                                }
    
  • #104378

    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.