Windows Script to Remove "_T0x" at the end of the files.

Everything related to MakeMKV
Post Reply
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

Hi All,

Thought I'd share a simple script I wrote to remove the "_T00" part at the end of the files. It's Windows only, though. Usage is run the file, then enter the directory where the files are located, and press OK. It will recursively check the folders inside that folder, and any .mkv or .mp4 file it finds in there with "_txx" or " txx" (where xx = two numbers), it will get rid of it.

Copy the code, and save it in a file entitled "whatever.vbs" (the .vbs file is the important part)

Yes it works, no it's not a virus, yes it could be optimised etc. However, it works well.

If you will always be using the same folder, save time by changing the first line to:
start_folder = "full_path_to_folder"
(ie, start_folder = "C:\Video_rips")

Code: Select all

start_Folder = InputBox ("Folder to Search Sub-Folders for: ")
Set WshShell = WScript.CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")'
Set Folder = objFSO.GetFolder(start_Folder)
changed_files = ""
count = 0
ShowSubFolders Folder
WScript.Echo ("Changes Made: " & count)
If count <> 0 Then
	WScript.Echo "Files Affected:" & vbcrlf & changed_files
End If

Sub ShowSubFolders(Folder)
	Set objFolder = objFSO.GetFolder(Folder.Path)
    Set allFiles = objFolder.Files
	For Each objFile in allFiles
		On Error Resume Next
		If lcase(objFSO.GetExtensionName(objFile.Name)) = "mkv" or lcase(objFSO.GetExtensionName(objFile.Name)) = "mp4" Then
			temp = Right(objFile.Name,8)
			temp = Left(temp,4)
			If Left(temp,1) = " " or Left(temp,1) = "_" Then
				If IsNumeric(Right(temp,2)) = True Then
					If lcase(Mid(temp,2,1)) = "t" Then
						new_name = Left(objFile.Path,Len(objFile.Path)-8) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
						new_name1 = Left(objFile.Name,Len(objFile.Name)-8) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
						changed_files = changed_files & objFile.Name  & " -> " & new_name1 & vbcrlf
						objFSO.MoveFile objFile.Path, new_name
						count = count + 1
					End If
				End If
			End If
		End If
	Next
	
    For Each Subfolder in Folder.SubFolders
        ShowSubFolders Subfolder
    Next
End Sub
Woodstock
Posts: 9912
Joined: Sun Jul 24, 2011 11:21 pm

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Woodstock »

It is always best, where possible, to present things like this in source form. At the very least, it gives people on other platforms than Windows an idea of what they could do themselves.

An enhancement that would make sense is to do a string replacement on "_" with a space, before applying the rename. Then it would be the "universal MakeMKV file name cleanup utility for Windows". ;)
MakeMKV Frequently Asked Questions
How to aid in finding the answer to your problem: Activating Debug Logging
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

Woodstock wrote:It is always best, where possible, to present things like this in source form. At the very least, it gives people on other platforms than Windows an idea of what they could do themselves.

An enhancement that would make sense is to do a string replacement on "_" with a space, before applying the rename. Then it would be the "universal MakeMKV file name cleanup utility for Windows". ;)
Hey Woodstock,

Makes sense. I'll revise it, and upload it soon.

When you say "present in source form", is this not in source form? Or do you mean pseudocode?
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

New source code: this will also replace all underscores with a space

Code: Select all

start_Folder = InputBox ("Folder to Search Sub-Folders for: ")
Set WshShell = WScript.CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")'
Set Folder = objFSO.GetFolder(start_Folder)
changed_files = ""
count = 0
ShowSubFolders Folder
WScript.Echo ("Changes Made: " & count)
If count <> 0 Then
	WScript.Echo "Files Affected:" & vbcrlf & changed_files
End If

Sub ShowSubFolders(Folder)
	Set objFolder = objFSO.GetFolder(Folder.Path)
    Set allFiles = objFolder.Files
	For Each objFile in allFiles
		On Error Resume Next
		If lcase(objFSO.GetExtensionName(objFile.Name)) = "mkv" or lcase(objFSO.GetExtensionName(objFile.Name)) = "mp4" Then
			temp = Right(objFile.Name,8)
			temp = Left(temp,4)
			If Left(temp,1) = " " or Left(temp,1) = "_" Then
				If IsNumeric(Right(temp,2)) = True Then
					If lcase(Mid(temp,2,1)) = "t" Then
						new_name = Left(objFile.Path,Len(objFile.Path)-8) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
						new_name = Left(new_name,InStrRev(new_name,"\")) + Replace(new_name,"_"," ",InStrRev(new_name,"\")+1)
						new_name1 = Left(objFile.Name,Len(objFile.Name)-8) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
						changed_files = changed_files & objFile.Name  & " -> " & new_name1 & vbcrlf
						objFSO.MoveFile objFile.Path, new_name
						count = count + 1
					End If
				End If
			End If
		End If
	Next
	
    For Each Subfolder in Folder.SubFolders
        ShowSubFolders Subfolder
    Next
End Sub
Woodstock
Posts: 9912
Joined: Sun Jul 24, 2011 11:21 pm

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Woodstock »

I was referring to exactly how you were releasing this - in source form. I was actually complimenting you on that. :)

Providing a compiled version is sometimes necessary for some users, but it source works for me.
MakeMKV Frequently Asked Questions
How to aid in finding the answer to your problem: Activating Debug Logging
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

Woodstock wrote:I was referring to exactly how you were releasing this - in source form. I was actually complimenting you on that. :)
Oh, ok. It's just weird to receive compliments on scripts rather than criticism. Thanks! :)
elviejo
Posts: 7
Joined: Sat May 28, 2016 4:12 pm

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by elviejo »

Could be possible to adapt the code to T000 instead of T00, obfuscation method usually have in excess of 99 files e.g. " The Expendables 3 " where the correct playlist is the 171, so the actual code won't work. Thanks in advance. :D
Krawk
Posts: 272
Joined: Thu Jul 02, 2015 12:10 am

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Krawk »

I'm still waiting for consistency in the program's naming of files.

Many times I get title00.mkv, rarely do I get Discname_t00.mkv
Why does it do it sometimes and not?
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

Krawk wrote: Many times I get title00.mkv, rarely do I get Discname_t00.mkv
Why does it do it sometimes and not?
Are you naming the files yourself? It sounds like you're accepting the default name, or not naming them. If you go to View->Preferences->General->Expert Mode (tick the box), you can name individual titles. When you name it yourself, the naming convention changes to "Name_You_Gave_It_t00.mkv". This is when you would use the above script to remove the _t00 section of the name. Also has the benefit of naming it correctly straight away.
elviejo
Posts: 7
Joined: Sat May 28, 2016 4:12 pm

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by elviejo »

elviejo wrote:Could be possible to adapt the code to T000 instead of T00, obfuscation method usually have in excess of 99 files e.g. " The Expendables 3 " where the correct playlist is the 171, so the actual code won't work. Thanks in advance. :D
bump
Yugatha
Posts: 86
Joined: Fri Jun 08, 2012 1:20 am
Location: The Land Down Under

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by Yugatha »

elviejo wrote:
elviejo wrote:Could be possible to adapt the code to T000 instead of T00, obfuscation method usually have in excess of 99 files e.g. " The Expendables 3 " where the correct playlist is the 171, so the actual code won't work. Thanks in advance. :D
bump
Haven't got the time to incorporate it into one script, but the below will remove "_t000" (and remove underlines). Use both scripts to remove "_t01" and "_t001" suffixes

Code: Select all

start_Folder = InputBox ("Folder to Search Sub-Folders for: ")
Set WshShell = WScript.CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")'
Set Folder = objFSO.GetFolder(start_Folder)
changed_files = ""
count = 0
ShowSubFolders Folder
WScript.Echo ("Changes Made: " & count)
If count <> 0 Then
   WScript.Echo "Files Affected:" & vbcrlf & changed_files
End If

Sub ShowSubFolders(Folder)
   Set objFolder = objFSO.GetFolder(Folder.Path)
    Set allFiles = objFolder.Files
   For Each objFile in allFiles
      On Error Resume Next
      If lcase(objFSO.GetExtensionName(objFile.Name)) = "mkv" or lcase(objFSO.GetExtensionName(objFile.Name)) = "mp4" Then
         temp = Right(objFile.Name,9)
         temp = Left(temp,5)
         If Left(temp,1) = " " or Left(temp,1) = "_" Then
            If IsNumeric(Right(temp,2)) = True Then
               If lcase(Mid(temp,2,1)) = "t" Then
                  new_name = Left(objFile.Path,Len(objFile.Path)-9) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
                  new_name = Left(new_name,InStrRev(new_name,"\")) + Replace(new_name,"_"," ",InStrRev(new_name,"\")+1)
                  new_name1 = Left(objFile.Name,Len(objFile.Name)-9) & "." + lcase(objFSO.GetExtensionName(objFile.Name))
                  changed_files = changed_files & objFile.Name  & " -> " & new_name1 & vbcrlf
                  objFSO.MoveFile objFile.Path, new_name
                  count = count + 1
               End If
            End If
         End If
      End If
   Next
   
    For Each Subfolder in Folder.SubFolders
        ShowSubFolders Subfolder
    Next
End Sub
elviejo
Posts: 7
Joined: Sat May 28, 2016 4:12 pm

Re: Windows Script to Remove "_T0x" at the end of the files.

Post by elviejo »

Thanks, work like a charm :D
Post Reply