niklas Posted March 17, 2010 Share Posted March 17, 2010 (edited) I made a script that gives subtitles the same name that videos have. Mostly because I watch a lot of tv shows and renaming many seasons of subtitles is really boring. The script is working so I thought I'd share it if someone else wants it, and perhaps get some advice on how to improve it? I'm no good with Autoit so the code might look 'newbish' There's one catch, the script finds the first .srt and the first .avi in the folder, gives them the same name then moves on to the next. So the files must be in perfect order or they will be all mixed up. expandcollapse popupGlobal $fileavi Global $filesrt Global $filesrt2 Global $fileavi2 ; Sets ESC to terminate the script. HotKeySet("{ESC}", "Terminate") Func Terminate() Exit 0 EndFunc ; Search for all .srt files. $searchsrt = FileFindFirstFile("*.srt") ; Check if the search was successful If $searchsrt = -1 Then MsgBox(0, "Error", "Can't find any .srt files (must be located in same dir.") Exit EndIf ; Search for all .avi files. $searchavi = FileFindFirstFile("*.avi") ; Check if the search was successful If $searchavi = -1 Then MsgBox(0, "Error", "Can't find any .avi files (must be located in same dir.)") Exit EndIf findsub() ; Find the first/next .srt file. Func findsub() $filesrt = FileFindNextFile($searchsrt) If @error Then Exit $filesrt2 = StringTrimRight($filesrt, 3) findavi() EndFunc ; Find the first/next .avi file & check if the subtitle needs to be renamed. Func findavi() $fileavi = FileFindNextFile($searchavi) If @error Then Exit $fileavi2 = StringTrimRight($fileavi, 3) If $filesrt2 = $fileavi2 Then findsrt() Else rename() EndIf EndFunc ; Give the subtitle the same name as the video (.avi). Func rename() FileMove($filesrt, $fileavi2 & "srt") findsub() EndFunc ; Close the search handle FileClose($searchsrt) FileClose($searchavi) Edited March 17, 2010 by niklas Link to comment Share on other sites More sharing options...
jvanegmond Posted March 17, 2010 Share Posted March 17, 2010 Instead of Call("findsub") you should (read: must) use findsub(). Same with findsrt, rename, etc.etc. github.com/jvanegmond Link to comment Share on other sites More sharing options...
niklas Posted March 17, 2010 Author Share Posted March 17, 2010 wow fast reply, thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now