Page 1 of 1

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

Posted: Sun Apr 05, 2015 2:06 pm
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

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

Posted: Sun Apr 05, 2015 2:24 pm
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". ;)

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

Posted: Sun Apr 05, 2015 2:27 pm
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?

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

Posted: Sun Apr 05, 2015 2:49 pm
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

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

Posted: Sun Apr 05, 2015 11:03 pm
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.

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

Posted: Mon Apr 06, 2015 12:01 am
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! :)

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

Posted: Sat May 28, 2016 4:17 pm
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

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

Posted: Thu Jun 02, 2016 1:26 am
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?

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

Posted: Thu Jun 02, 2016 1:40 am
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.

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

Posted: Thu Jun 02, 2016 1:47 am
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

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

Posted: Thu Jun 02, 2016 2:39 am
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

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

Posted: Thu Jun 02, 2016 2:43 am
by elviejo
Thanks, work like a charm :D