Question Rename filename after Title ?

cube10025

Distinguished
Sep 6, 2016
28
0
18,530
Hello.
I have recovered RAW files from a drive and need to rename them form the dynamic to the title name. Se pic below. Powershell? Probable need if no title ignore.

title_2.jpg
 
Not sure about your question....

If you right click the name of the file then a menu option to Rename the file should presented.

Then left click Rename and go from there.

Note: Rename does not appear as an option if you are clicking a file in "Recent files".
 
I don't quite understand the question either.
How many files need to be renamed? If not too many, manually renaming them one by one is the most straightforward approach. If there are hundreds or thousands, there are batch renaming approaches.
 
You mention PowerShell.

I found this link and copied and modified from it:

The script below will rename all the MP3 and MP4 files in the folder you specify to the name of the title from the metadata of each file. If the title contains colons, they are replaced with a minus/dash. If a file contains no title the file is ignored.
Code:
Function Get-MPegMetaData
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([Psobject])]
    Param
    (
        [String] [Parameter(Mandatory=$true, ValueFromPipeline=$true)] $Directory
    )

    Begin
    {
        $shell = New-Object -ComObject "Shell.Application"
    }
    Process
    {

        Foreach($Dir in $Directory)
        {
            $ObjDir = $shell.NameSpace($Dir)
            $Files = gci $Dir| ?{$_.Extension -in '.mp3','.mp4'}

            Foreach($File in $Files)
            {
                $ObjFile = $ObjDir.parsename($File.Name)
                $MetaData = @{}
                $MP3 = ($ObjDir.Items()|?{$_.path -like "*.mp3" -or $_.path -like "*.mp4"})
                $PropertArray = 0,1,2,12,13,14,15,16,17,18,19,20,21,22,27,28,36,220,223

                Foreach($item in $PropertArray)
                {
                    If($ObjDir.GetDetailsOf($ObjFile, $item)) #To avoid empty values
                    {
                        $MetaData[$($ObjDir.GetDetailsOf($MP3,$item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
                    }
 
                }

                New-Object psobject -Property $MetaData |select *, @{n="Directory";e={$Dir}}, @{n="Fullname";e={Join-Path $Dir $File.Name -Resolve}}, @{n="Extension";e={$File.Extension}}
            }
        }
    }
    End
    {
    }
}

# Replace the path below with the path to your mp3 or mp4 files
ForEach($item in ("C:\Path\To\Folder\Containg\Mp4\files" | Get-MPegMetaData)) {
    if ($item.Title.Length -gt 0) {
        $Title = [regex]::Replace($item.Title, ":", "-")
        $NewName = $Title + $item.Extension
        Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
    }
}

Save the script to a file with the .ps1 extension, for example test.ps1.

Then search the file for "C:\Path\To\Folder\Containg\Mp4\files" and replace it with the path to your MP4 files, or modify the script to take the path from the command line. Then save the file again.

Then run the script this way:
Code:
powershell.exe -executionpolicy bypass -file .\test.ps1
You should replace .\test.ps1 with the full path to your script, if you are not running the script from the command line, with the folder of test1.ps as the current working directory.

You should take a backup before running the script, as I haven't tested it thoroughly. I ran the script using Windows PowerShell ISE on a folder containing MP3 files and it worked for me.
 
Last edited:
i used this when i had to rename thousands of mp3 files


it'll pull the info from the tag if it is there and correct, to rename the file. been a while since i used it but it worked great for me :)
 
Or you can try do something complete different.

If you have access to a Linux (with regular desktop OS) computer, you can drop all those files into the storage of the Linux computer without renaming.

Reason for this is that Linux doesn't use file endings (.mp3 .txt etc) to identify file type, but rather the file heading - at least for known file types.
 
Or you can try do something complete different.

If you have access to a Linux (with regular desktop OS) computer, you can drop all those files into the storage of the Linux computer without renaming.

Reason for this is that Linux doesn't use file endings (.mp3 .txt etc) to identify file type, but rather the file heading - at least for known file types.

But the file endings is fine, I need to rename them to there proper name like in the title in the metadata.
 
If I run.

Get-MPegMetaData -Directory "C:\test\test2" I get works fine, the title is there

But the script dose nothing, what am i missing?


Code:
Function Get-MPegMetaData

{

    [CmdletBinding()]

    [Alias()]

    [OutputType([Psobject])]

    Param

    (

        [String] [Parameter(Mandatory=$true, ValueFromPipeline=$true)] $Directory

    )



    Begin

    {

        $shell = New-Object -ComObject "Shell.Application"

    }

    Process

    {



        Foreach($Dir in $Directory)

        {

            $ObjDir = $shell.NameSpace($Dir)

            $Files = gci $Dir| ?{$_.Extension -in '.mp3','.mp4'}



            Foreach($File in $Files)

            {

                $ObjFile = $ObjDir.parsename($File.Name)

                $MetaData = @{}

                $MP3 = ($ObjDir.Items()|?{$_.path -like "*.mp3" -or $_.path -like "*.mp4"})

                $PropertArray = 0,1,2,12,13,14,15,16,17,18,19,20,21,22,27,28,36,220,223



                Foreach($item in $PropertArray)

                {

                    If($ObjDir.GetDetailsOf($ObjFile, $item)) #To avoid empty values

                    {

                        $MetaData[$($ObjDir.GetDetailsOf($MP3,$item))] = $ObjDir.GetDetailsOf($ObjFile, $item)

                    }



                }



                New-Object psobject -Property $MetaData |select *, @{n="Directory";e={$Dir}}, @{n="Fullname";e={Join-Path $Dir $File.Name -Resolve}}, @{n="Extension";e={$File.Extension}}

            }

        }

    }

    End

    {

    }

}



# Replace the path below with the path to your mp3 or mp4 files

ForEach($item in ("C:\test\test2" | Get-MPegMetaData)) {

    if ($item.Title.Length -gt 0) {

        $Title = [regex]::Replace($item.Title, ":", "-")

        $NewName = $Title + $item.Extension

        Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force

    }

}



title2.jpg
 
There problem seem to be English and Swedish, need to replace with Title "Titel", but now I am getting "cannot create a file when that file already exists"

Yeah, the title tag in your file was in Swedish, not English. I am curious as to how other renaming tools handle the title tag, when it's localized.

Also note that the title may contain other illegal characters. I only replaced colon, but slash, backslash, pipe and other characters should be replaced too. If that's not what is causing your renaming error, I'd have t o test it myself to determine what the bug is.

I prefer to have the source code for the tools I am using, and improve them over time.
 
Also note that the title may contain other illegal characters. I only replaced colon, but slash, backslash, pipe and other characters should be replaced too. If that's not what is causing your renaming error, I'd have t o test it myself to determine what the bug is.

MP3 tag don´t do mkv for some reason.

I´l look at the characters,
google suggests the you can not use rename-item but should use move-item, but you tested? Should work?
Feels like the error should be being used by another process rather than "can not create a file when that file already exists" missleading error?
 
MP3 tag don´t do mkv for some reason.

I haven't tested with mkv. Will test later.

Feels like the error should be being used by another process rather than "can not create a file when that file already exists" missleading error?

I get no errors if I run the script twice on the same folder, which causes the already renamed files to be renamed to themselves. So the error is probably due to something else, I will test later.

I have some work to do, so will probably wait until the weekend.