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

 
Keymaster
5 months ago.

  • Author
    Posts
  • #104351

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

    Keymaster
    Points: 1,704
    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.