alish Posted March 4, 2010 Share Posted March 4, 2010 Hello Im noob here and will appreciate your help. This is what I need to do : 1. Find files based on their names - Not content inside the files, just words that conclude the file names. i.e. "Excel2007.exe" -> I need to find the word "Word" 2. add random letters\words to their names 3. Move them to another location, each file should be moved according to its name. I couldn't find how to find a word within a filename. Thanks ahead guys! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2010 Moderators Share Posted March 4, 2010 alish,Welcome to the AutoIt forum. You can use StringInStr to search for partial matches within strings - although the example you gave would fail :$iRetValue = StringInStr("Excel2007.exe", "Word") ; This will fail and return 0 $iRetValue = StringInStr("Excel2007.exe", "Excel") ; This will succeed and return 1There is no rename function in AutoIt, so you will have to do the other 2 operations at the same time using FileMove:$sFileName = "Excel2007.exe" ; Break the name down $sFileNameOnly = StringRegExpReplace($sFileName, "^.*\\|\..*$", "") $sFileDotExt = StringRegExpReplace($sFileName, "^.*\.", ".$1") ; Add what you want to the file name $sNewFileNameOnly = $sFileNameOnly & "_001" ; for example, here we add _001 ; Recontrwuct the whole $sNewFileName = $sNewFileNameOnly & $sFileDotExt ; It will read "Excel2007_001.exe" ; And finally move the file FileMove($sFileName, $sNewFileName) ; you will have to add path info here to make it workRight, over to you! You know where we are if you run into problems. 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...
alish Posted March 4, 2010 Author Share Posted March 4, 2010 Thank you very much for taking the time to reply, I greatly appreciate it. I think I dropped certain details. I have a folder that contains a lot of files. I need these files to be distributed to their correspondent folders, based on their names. i.e. if I have a file that named 2010-36-72-NN.ISO I want it to be renamed and moved to a folder called 36-72. The problem is that there are a lot of fies i.e. 2010-36-72-NN3.ISO 2010-36-72-NN7.ISO 2010-36-72-NN8.ISO 2010-22-44-NN0.ISO 2010-22-44-NN1.ISO 2010-22-44-NN7.ISO In the example you provided, you showed how to find a word within a file you already know its name. I hope it helps you to understand my needs, and thanks in advance Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2010 Moderators Share Posted March 4, 2010 alish,Yes, it would have helped if you had explained what you wanted to do at the beginning and saved my fingers from all that typing! To extract the 36-72 from 2010-36-72-NN?.ISO is not too difficult - we will have to use StringRegExp. How would you want to rename the file? Can you give some examples like this:original name New name Move to folder 2010-22-44-NN0.ISO 001.fil 22-44 2010-36-72-NN7.ISO 002.fil 36-72I do hope there is a pattern to the renaming! 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...
dani Posted March 5, 2010 Share Posted March 5, 2010 (edited) I'll just contribute some code to move files to new locations, you can edit this where needed. I trust Melba will help you along. Excuse me for the indent size of 2, Ruby's standards taking over MoveFiles(@ScriptDir, "ISO") Func MoveFiles($hDir, $ext) FileChangeDir($hDir) $hSearch = FileFindFirstFile("*.*") $hFile = FileFindNextFile($hSearch) While Not @error If @extended Then ; $hFile is a directory MoveFiles($hDir & "\" & $hFile, $ext) ; Scan the subdirectory. Remove this if you want to exclude subdirs, of course Else ; $hFile is a file FileChangeDir($hDir) If StringRegExp($hFile, "(?i)\." & $ext & "\z") Then $hFile = "SomeOtherName." & $ext ; Rename $hFile here if needed $target = "C:\TargetDirectory" ; Set $target (= directory) to something useful here FileMove($hFile, $target, 8+1) ; Move $hFile to $target (create directory if needed and overwrite existing files -- flag 8+1) EndIf $hFile = FileFindNextFile($hSearch) WEnd FileClose($hSearch) EndFunc Edited March 5, 2010 by dani 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