2

I've just finished creating SHA1 hashes for each album in my MP3 collection using Corz Checksum. It left a .hash file in each folder, as desired. (Each folder is an album.)

However, the hash files it generated all have the name of the folder, for example

The Beatles - 1966 - Revolver.hash

I would like to automatically rename all of these .hash files to match the name of the .m3u playlist file which every folder also contains. For example the presence of

00 - Revolver.m3u

should cause the hash file to be renamed to

00 - Revolver.hash

Does anyone know of a way to do this with a command line? I'm hoping to find something similar to this: Which command can I use to recursively rename or move a file in Windows?

1

You can do this with PowerShell, if you're comfortable with that.

function Rename-HashFiles ([string]$path)
{
    [System.IO.FileInfo[]]$hashFiles = Get-ChildItem -Path $path -Force -Include "*.hash" -Recurse
    foreach($hashFile in $hashFiles)
    {
        [string]$newFileName = [string]::Empty;
        Get-ChildItem -Path ($hashFile.DirectoryName) -Filter "*.m3u" | % { $newFileName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name) }    
        $newFileName += ([System.IO.Path]::GetExtension($hashFile.Name))
        Rename-Item -Path $hashFile.FullName -NewName $newFileName
    }

}

Rename-HashFiles "C:\My_Music_Folder"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.