Remove last 2 characters in all files in a folder

January 11, 2012 at 13:55:35
Specs: Windows XP
Hello guys! Its been a while since I have been on here, so I am not as good at coding as I once was. My problem is I have converted a ton of files from .flv to .mp3, and the converter automatically adds 2 characters onto the file name. I obviously don't want to manually go though and remove those last two characters, so I was hoping that a batch script could do it for me.

If anyone can help me out with a script to do this, it would be much appreciated!

See More: Remove last 2 characters in all files in a folder

Report •

January 11, 2012 at 16:27:18
Never mind. I found a script that does it only its coded in AHK (AutoHotKey). If anyone in the future wants it, its below. It launches automatically, and if you are going to use it, you will need to learn how the commands work and modify it to work for your situation.

FileList =  ; Initialize to be blank.
Loop, C:\Documents and Settings\David\Desktop\New Folder\*.*
FileList = %FileList%%A_LoopFileName%`n
Sort, FileList
Loop, parse, FileList, `n
	if A_LoopField =  ; Ignore the blank item at the end of the list.
	StringTrimRight, A_LoopFieldAfter, A_LoopField, 6
	A_LoopFieldAfter = %A_LoopFieldAfter%.mp3
	FileMove, C:\Documents and Settings\David\Desktop\New Folder\%A_LoopField%, C:\Documents and Settings\David\Desktop\New Folder\%A_LoopFieldAfter%, 0
	MsgBox, Done!

Report •
Related Solutions

Ask Question