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
}
}
powershell.exe -executionpolicy bypass -file .\test.ps1
The script below will rename all the MP3 and MP4 files
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.
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
}
}
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"
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.
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?