SAEED Posted April 29, 2009 Share Posted April 29, 2009 ----------------------------------------------------------------------------------------------------------------------------------------------- #include <Array.au3> Global $locations = "C:\Documents and Settings\Administrator\My Documents\My Pictures\" Local $i, $get = False Dim $Found_Files[1] $Total_files = DirGetSize($locations, 3) $Fh = FileFindFirstFile($locations & "*.*") $i = 0 While 1 $found = FileFindNextFile($Fh) If @error Then ExitLoop ;~ ConsoleWrite($found&@CRLF) $34 = StringReplace($locations&$found, $found, "PICTURE"&$i&".JPG",0) ConsoleWrite($34&@CRLF) If $Found_Files[0] = "" Then _ArrayPush($Found_Files, $34, 1) Else _ArrayAdd($Found_Files, $34) EndIf $i += 1 WEnd _ArrayDisplay($Found_Files, "Search Result") ----------------------------------------------------------------------------------------------------------------------------------------------- I want to rename that files via Autoit i desing this script but it does not files rename so help me in this script.Files_Rename.au3 Link to comment Share on other sites More sharing options...
CodyBarrett Posted April 29, 2009 Share Posted April 29, 2009 filemove () and use a different name for the output will rename it [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 29, 2009 Moderators Share Posted April 29, 2009 SAEED,First, welcome to the AutoIt forums.A good start - some code to work on and a clear question. I wish some others would do the same. :-)From the Help file: "Because AutoIt lacks a "FileRename" function, use FileMove to rename a file!". So we need to get a list of all the files (your code basically does that already) and then loop through them with FileMove to change their names.Have a look at this:#include <Array.au3> Global $locations = "C:\Documents and Settings\Administrator\My Documents\My Pictures\" Local $i, $get = False Global $Found_Files[1] ; Try not to use Dim! $Total_files = DirGetSize($locations, 3) $Fh = FileFindFirstFile($locations & "*.*") While 1 $found = FileFindNextFile($Fh) If @error Then ExitLoop ConsoleWrite($found & @CRLF) If $Found_Files[0] = "" Then _ArrayPush($Found_Files, $found, 1) Else _ArrayAdd($Found_Files, $found) EndIf WEnd FileClose($Fh) ; You should close the Search file handle! _ArrayDisplay($Found_Files, "Search Result") For $i = 0 To UBound($Found_Files) - 1 FileMove($locations & $Found_Files[$i], $locations & "PICTURE" & $i & ".JPG", 0) NextThe array is now a list of all the files in your folder with their current names. The final loop then renames them using FileMove.2 other points:1 - You should close the search file handle when the search is over. Tha tHelpfile again: "When you have finished searching with the FileFind... functions you must call FileClose() to release the search handle."2. Do not use Dim (unless you want to empty an existing array) - Global/Local are much better as they scope the array immediately.Ask if you have any questions.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SAEED Posted April 29, 2009 Author Share Posted April 29, 2009 Thanks alot Dear to solve my problam, its true i am a new user of Autoit. i am designing an other program like a Windows "search" but i have some problam in my "search Program". If u dont mind can i send my script to you for better solution. waiting ur Nice Reply.. M-SAEED Link to comment Share on other sites More sharing options...
Developers Jos Posted April 29, 2009 Developers Share Posted April 29, 2009 Thanks alot Dear to solve my problam..Sorry Melba23, but this did put a smile on my face SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
DaRam Posted April 29, 2009 Share Posted April 29, 2009 Saeed, Try and reuse a single post/thread for issues/help ! #675898Thanks alot Dear to solve my problam, its true i am a new user of Autoit.M-SAEED Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 29, 2009 Moderators Share Posted April 29, 2009 SAEED,The forum is here so the whole community can benefit. If you have a problem with your "search" script, please open a new thread - that way many forum members can help and (perhaps) learn! Sending PMs asking for help is frowned upon here. ;-)When you do post your script, please use Code tags - put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here). Jos,I had exactly the same reaction - quite made my day! :-)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MSF Posted June 5, 2009 Share Posted June 5, 2009 SAEED, First, welcome to the AutoIt forums. A good start - some code to work on and a clear question. I wish some others would do the same. :-) From the Help file: "Because AutoIt lacks a "FileRename" function, use FileMove to rename a file!". So we need to get a list of all the files (your code basically does that already) and then loop through them with FileMove to change their names. Have a look at this:#include <Array.au3> Global $locations = "C:\Documents and Settings\Administrator\My Documents\My Pictures\" Local $i, $get = False Global $Found_Files[1]; Try not to use Dim! $Total_files = DirGetSize($locations, 3) $Fh = FileFindFirstFile($locations & "*.*") While 1 $found = FileFindNextFile($Fh) If @error Then ExitLoop ConsoleWrite($found & @CRLF) If $Found_Files[0] = "" Then _ArrayPush($Found_Files, $found, 1) Else _ArrayAdd($Found_Files, $found) EndIf WEnd FileClose($Fh) ; You should close the Search file handle! _ArrayDisplay($Found_Files, "Search Result") For $i = 0 To UBound($Found_Files) - 1 FileMove($locations & $Found_Files[$i], $locations & "PICTURE" & $i & ".JPG", 0) Next The array is now a list of all the files in your folder with their current names. The final loop then renames them using FileMove. 2 other points: 1 - You should close the search file handle when the search is over. Tha tHelpfile again: "When you have finished searching with the FileFind... functions you must call FileClose() to release the search handle." 2. Do not use Dim (unless you want to empty an existing array) - Global/Local are much better as they scope the array immediately. Ask if you have any questions. M23Instead of renaming the files with PICTURE & $i, would it be possible to rename the files with the same name but stripped of unwanted characters? Or perhaps strip the unwanted character before it's stored in the array? Such as... Old Names 12345_r.tif 123456_c.tif New Names 12345r.tif 123456c.tif Link to comment Share on other sites More sharing options...
Skruge Posted June 5, 2009 Share Posted June 5, 2009 Instead of renaming the files with PICTURE & $i, would it be possible to rename the files with the same name but stripped of unwanted characters? Or perhaps strip the unwanted character before it's stored in the array? Such as... Old Names 12345_r.tif 123456_c.tif New Names 12345r.tif 123456c.tifSince the original names are needed for the rename, the array should contain unaltered information. (Unless you store this elsewhere)FileMove($locations & $Found_Files[$i], $locations & StringReplace($Found_Files[$i], "_", ""), 0) [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
MSF Posted June 8, 2009 Share Posted June 8, 2009 Since the original names are needed for the rename, the array should contain unaltered information. (Unless you store this elsewhere)FileMove($locations & $Found_Files[$i], $locations & StringReplace($Found_Files[$i], "_", ""), 0)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