godspeedcapri Posted February 17, 2006 Share Posted February 17, 2006 Hi , I am trying to write a script which can change file extensions for all files under a specified directory. I looked around in this forum and in the help file. There is no function to rename files. I am extracting the last three bits of the file extension using StringRight function. Could someone suggest as to how I can replace the last three bits of the file name. Ta. GodspeedCapri Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Share Posted February 17, 2006 (edited) Maybe $ext = .txt $filename = My-GUI.au3 $filename = stringtrimright( $filename, 4 ) $filename = $filename & $ext thus..... $filename = My-GUI.txt 8) Edited February 17, 2006 by Valuater Link to comment Share on other sites More sharing options...
herewasplato Posted February 17, 2006 Share Posted February 17, 2006 ...a script which can change file extensions for all files under a specified directory.I would do it via DOS:rename "C:\Temp\New Folder\*.*" "*.whatever"If you must script it, wrap a "Run" around it. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
godspeedcapri Posted February 17, 2006 Author Share Posted February 17, 2006 ; ---------------------------------------------------------------------------- ; ; AutoIt Version: ; Author: GodSpeedCapri ; ; Script Function: ; Delete Temporary files in specific locations ; ; ---------------------------------------------------------------------------- $pathentered = InputBox("Folder Location", "Please Enter the exact location of folder") msgbox(0,"",$pathentered) ;$extension = InputBox("Extension","Enter the file extension required [eg: .txt,.doc,.jpg,.zoo]") $path = $pathentered & "\" msgbox(0,"",$path) $rnj = FileFindFirstFile($path & "*.*") while 1 $file = FileFindNextFile($rnj) msgbox(0,"",$file) if @error then ExitLoop if stringright($file,4) == ".mp3" or stringright($file,4) == ".txt" Then msgbox(0,"",$path) FileMove($path & "*.*", $path & "*.zoo",9) Else Endif WEnd The above is what I am trying to..Does not work as intended... Also the StringRegExp does not work with AutoIT Beta version.??? Link to comment Share on other sites More sharing options...
Valuater Posted February 17, 2006 Share Posted February 17, 2006 maybe this ; ---------------------------------------------------------------------------- ; ; AutoIt Version: ; Author: GodSpeedCapri ; ; Script Function: ; Delete Temporary files in specific locations ; ; ---------------------------------------------------------------------------- $pathentered = FileSelectFolder("Choose a folder.", "") ;$pathentered = InputBox("Folder Location", "Please Enter the exact location of folder") MsgBox(0, "", $pathentered) $extension = InputBox("Extension","Enter the file extension required [eg: .txt,.doc,.jpg,.zoo]") $path = $pathentered & "\" MsgBox(0, "", $path) $rnj = FileFindFirstFile($path & "*.*") While 1 $file = FileFindNextFile($rnj) MsgBox(0, "", $file) If @error Then ExitLoop If StringRight($file, 4) == ".mp3" Or StringRight($file, 4) == ".txt" Then MsgBox(0, "", $path) $newfile = StringTrimRight($file, 4) FileMove($path & $file, $path & $newfile & $extension, 9) EndIf WEnd not tested 8) Link to comment Share on other sites More sharing options...
MHz Posted February 17, 2006 Share Posted February 17, 2006 No need to test it Valuater, as MsgBox does not return error so the exitloop will never work. Just thought you would like to know. Link to comment Share on other sites More sharing options...
Nuffilein805 Posted February 17, 2006 Share Posted February 17, 2006 i love those kind of mistakes those are my favorite (trying to do this in every script - well not trying, i'm a pro, i manage to do it in every script ) my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 17, 2006 Moderators Share Posted February 17, 2006 I'm going to start sending MHz all my scripts to proof them, I can only imagine how much more efficient I'd be!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nuffilein805 Posted February 17, 2006 Share Posted February 17, 2006 i'm sure he will love to check all your scripts maybe you could do a little combo-script (maybe 50of your scripts together in 1) and let him check i'm going to think about this as well - nice idea mhz what do you think - wanna be the autoit-free-to-use-script-checker? my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
MHz Posted February 17, 2006 Share Posted February 17, 2006 I'm going to start sending MHz all my scripts to proof them, I can only imagine how much more efficient I'd be!! Good Idea, just send them to MHz@dodgeit.com Include all your backup scripts also for safe handling. Link to comment Share on other sites More sharing options...
dabus Posted February 17, 2006 Share Posted February 17, 2006 (edited) I'd always search for the correct suffix, since the length will not always be the same (htm/html/au). This works for me: $a = 0 While 1 $a = $a + 1 $Error = StringInStr($File, ".", 0, $a) If $Error = 0 Then $Pos = StringInStr($File, ".", 0, $a - 1) $Name = StringLeft($File, $Pos - 1) $Suffix = StringTrimLeft($File, $Pos) ExitLoop EndIf WEnd Edited February 17, 2006 by dabus Link to comment Share on other sites More sharing options...
herewasplato Posted February 18, 2006 Share Posted February 18, 2006 Your original post states that you wish to change the file extensions for all files in a folder and yet the code that you posted has a line like this: If StringRight($file, 4) == ".mp3" Or..... and a description that reads: Delete Temporary files in specific locations...so I'm a little confused...I changed what you posted into these 3 lines:$pathentered = FileSelectFolder("Choose a folder.", "") $extension = InputBox("Extension", "Enter the file extension required [eg: .txt, .doc, .jpg, .zoo]") RunWait(@ComSpec & " /c " & 'rename ' & '"' & $pathentered & '\*.*" "*' & $extension & '"')That code should replace all of the file extensions in the folder selected. I think that the DOS "rename" snytax has been the same since W95.If you want to specify what to replace and what to replace it with - try this code:$pathentered = FileSelectFolder("Choose a folder.", "") $ext1 = InputBox("Extension", "To be replaced [eg: .txt, .doc, .jpg, .zoo]") $ext2 = InputBox("Extension", "Replaced with [eg: .txt, .doc, .jpg, .zoo]") RunWait(@ComSpec & " /c " & 'rename ' & '"' & $pathentered & '\*' & $ext1 & '" "*' & $ext2 & '"')You can hide the "DOS window" if you wish....hope this helps... [size="1"][font="Arial"].[u].[/u][/font][/size] 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