Batch rename of folders (append with suffix)

Discussion in 'General Software' started by rhouck, Jan 23, 2011.

  1. rhouck

    rhouck 2[H]4U

    Messages:
    3,618
    Joined:
    Apr 15, 2002
    I am looking for a solution to batch rename folders from "Name" to "Name [FLAC]".

    My music is currently divided into two main folders: one for lossless (flac) files and one for all other (mainly mp3). I would like to consolidate them but would like to make it easy to see from a folder level which albums are lossless.

    The format is \\Quality\Artist\Album

    For example:
    \\Music-Lossless\A Perfect Circle\Mer de Noms
    \\Music\A Perfect Circle\Thirteenth Step

    I would like to have all the "Album" folders renamed to "Album [FLAC]".

    So "\\Music-Lossless\A Perfect Circle\Mer de Noms [FLAC]" would be the result.

    There are ~500 Artists in my Lossless folder, each with various Albums as subdirectories, thus the desire to have this done as a batch rename. It would need to be recursive down one folder level (as I'd prefer to not have to go artist-by-artist).

    Suggestions on programs or command line way to do this?
     
  2. devil22

    devil22 2[H]4U

    Messages:
    3,835
    Joined:
    Jan 1, 2003
    Here's a PowerShell script that does it, PowerShell is included in Windows 7, the first time you run PowerShell, you need to run it as Admin and run the command "Set-executionpolicy RemoteSigned" to enable you to run scripts. Save it as 'batchrename.ps1' and run it by typing '.\batchrename.ps1 [directory of Music-Lossless]' so for example '.\batchrename.ps1 c:\users\bob\music\music-lossless'

    Code:
    if ($args.count -ne 1) {echo "Requires 1 argument. Exiting."; exit}
    $musicdir=$args[0]
     
    if ((get-item -ea 0 $musicdir).exists -eq $false) {echo "$musicdir does not exist. Exiting.";exit}
     
    $artists=(dir (get-item $musicdir).fullname | ?{$_.mode -match "d"})
     
    foreach ($artist in $artists)
    {
        $albums = (dir $artist.fullname | ?{$_.mode -match "d"})
        foreach ($album in $albums)
        {
            mv -literalpath $album.fullname "$($album.fullname) [FLAC]"
        }
    }
     
  3. phide

    phide [H]ard as it Gets

    Messages:
    16,751
    Joined:
    Jun 11, 2004
  4. rhouck

    rhouck 2[H]4U

    Messages:
    3,618
    Joined:
    Apr 15, 2002
    Thanks for the help, I believe this will work perfectly for my needs.
     
  5. zero2dash

    zero2dash [H]ardness Supreme

    Messages:
    6,092
    Joined:
    Oct 23, 2007
    +1 I love ReNamer