Fateslayer Posted May 22, 2015 Share Posted May 22, 2015 (edited) Hi, I Need A Script Which Can Rename Files Automatically Based On A Template Like The Following Examples:Example 1:Original Name: Messaging_4.4.2-eng.nbc.1409734194_19After Renaming: Messaging 4.4.2Example 2:Original Name: Maps_9.9.0_909010124After Renaming: Maps 9.9.0Example 3:Original Name: Gmail_5.2.93937770_52000999After Renaming: Gmail 5.2.939The Script Reads The Name Of File Then Looks For A "_" Character And If It Finds The "_" Character It Replaces It With a Space(See Example 1, 2 and 3)Then It Looks For "." Character Followed By 3 Numbers(See Example 3). If It Finds It Then It Removes All The Character After The 3rd Digit Until The End Of File name(See Example 3).Else If It Finds A "_" OR "-" Character(See Example 1 and 3) Then The Script Removes All The Characters From "_" OR "-" Character Until The End Of File name (Including "_" OR "-" Character)NOTE: 1. The Script Should Allow Me To Browse And Select File(s).2. The Script Is Meant To Be Run On A Windows 8 Machine.I'm Not Good At AutoIt Yet So Please Help Me Out. Thank You Edited May 22, 2015 by Fateslayer Link to comment Share on other sites More sharing options...
Starstar Posted May 22, 2015 Share Posted May 22, 2015 we welcome you Fateslayer........I think there i no direct command to rename a file but don't worry i have solution send "F2" key is to be easiest way to rename a file. Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Fateslayer Posted May 22, 2015 Author Share Posted May 22, 2015 Thanks For The Grand Welcome Starstar . I hope you figure it out. I'm stuck at it since a long time. Link to comment Share on other sites More sharing options...
Starstar Posted May 22, 2015 Share Posted May 22, 2015 (edited) May be this one can help you........ Edited May 22, 2015 by Starstar Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Fateslayer Posted May 22, 2015 Author Share Posted May 22, 2015 I was hoping for a working script since I am a noob at AutoIt so I'll really appreciate a working script Link to comment Share on other sites More sharing options...
Starstar Posted May 22, 2015 Share Posted May 22, 2015 (edited) expandcollapse popup#include <File.au3> GUICreate("",250,150) $brwbtn = GUICtrlCreateButton("Browse",100,50,50,25) $Brwlnpt = GUICtrlCreateInput("",10,10,100,25) $renmebtn = GUICtrlCreateButton("Rename",40,50,50,25) GUISetState(@SW_SHOW) While 1 $gmsg = GUIGetMsg() Switch $gmsg Case $brwbtn $message = "Here you can type anything." Local $var = FileOpenDialog($message, @WorkingDir, "All (*.*)", 1 + 2,@ScriptName) If @error Then MsgBox(0, "", "No File chosen") Else $var = StringReplace($var, "|", @CRLF) EndIf ControlSetText("", "",$Brwlnpt , $var) Case $renmebtn $Gbrwr = GUICtrlRead($Brwlnpt) If StringLen($Gbrwr) = 0 Then MsgBox(64,"Error", "Please Browse Something") Else $Gbrwr = GUICtrlRead($Brwlnpt) Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" Local $aPathSplit = _PathSplit($var, $sDrive, $sDir, $sFilename, $sExtension) $freplace = StringReplace($sFilename,"-"," ") $frepalceAgn = StringReplace($freplace,"_"," ") $return = FileMove($aPathSplit[0],$sDrive&$sDir&$frepalceAgn&$sExtension) MsgBox(0,"",$return) EndIf Case -3 Exit EndSwitch WEnd Check this one.........[Edit:::]I am busy now after two days i shall start work on your remain script .........now it can only replace "-" & "_"to space..... Edited May 23, 2015 by Starstar Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Fateslayer Posted May 23, 2015 Author Share Posted May 23, 2015 Thank You So Much Bro. I Really Appreciate You Spending Your Time On This. You Are Awesome Link to comment Share on other sites More sharing options...
Starstar Posted May 23, 2015 Share Posted May 23, 2015 Thank You So Much Bro. I Really Appreciate You Spending Your Time On This. You Are AwesomeMy pleasure. Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Starstar Posted May 24, 2015 Share Posted May 24, 2015 (edited) expandcollapse popup#include <File.au3> #include <ColorConstants.au3> GUICreate("ReName Files",250,150) $brwbtn = GUICtrlCreateButton("Browse",190,50,50,25) $Brwlnpt = GUICtrlCreateInput("",10,10,230,25) $renmebtn = GUICtrlCreateButton("Rename",10,50,50,25) $lable = GUICtrlCreateLabel("Starstar",25,80,200,55) GUICtrlSetFont($lable,40,50) GUICtrlSetCursor($brwbtn, 0) GUICtrlSetCursor($renmebtn, 0) GUICtrlSetCursor($lable, 0) GUICtrlSetColor($lable, $COLOR_White) GUISetState(@SW_SHOW) While 1 $gmsg = GUIGetMsg() Switch $gmsg Case $brwbtn $message = "Here you can type anything." Local $var = FileOpenDialog($message, @WorkingDir, "All (*.*)", 1 + 2 + 4,@ScriptName) If @error Then MsgBox(0, "", "No File chosen") EndIf ControlSetText("", "",$Brwlnpt , $var) Case $renmebtn $Gbrwr = GUICtrlRead($Brwlnpt) If StringLen($Gbrwr) = 0 Then MsgBox(64,"Error", "Please Browse Something") Else $Gbrwr = GUICtrlRead($Brwlnpt) Local $aStringSplit = StringSplit($var,"|") If $aStringSplit[0] = 1 Then Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = "" Local $aPathSplit = _PathSplit($var, $sDrive, $sDir, $sFilename, $sExtension) $freplace1 = StringRegExpReplace($sFilename,"[-_]"," ") $return1 = FileMove($aPathSplit[0],$sDrive&$sDir&$freplace1&$sExtension) If $return1 = 0 Then MsgBox(0,"For Fateslayer","There is nothing to Replace in: '"&$sFilename&"'") ElseIf $return1 = 1 Then MsgBox(0,"For Fateslayer","Following File are Renamed Successfully: '"&$sFilename&"' to '"&$freplace1&"'") Else MsgBox(0,"Error",$return1) EndIf ElseIf $aStringSplit[0] > 1 Then For $i = 2 To $aStringSplit[0] $freplace = StringRegExpReplace($aStringSplit[$i],"[-_]"," ") $return = FileMove($aStringSplit[$i],$freplace) If $return = 0 Then MsgBox(0,"For Fateslayer","There is nothing to Replace in: '"&$aStringSplit[$i]&"'") ElseIf $return = 1 Then MsgBox(0,"For Fateslayer","Following File are Renamed Successfully: '"&$aStringSplit[$i]&"' to '"&$freplace&"'") Else MsgBox(0,"Error",$return) EndIf Next EndIf EndIf Case $lable ShellExecute("https://www.autoitscript.com/forum/profile/76662-starstar/") Case -3 Exit EndSwitch WEnd Here is multi-file Renamer.. Now you can select more than one file in browse option..... Edited May 24, 2015 by Starstar Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." 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