joopgoudvis Posted April 7, 2008 Share Posted April 7, 2008 (edited) Hello, I am trying too create a script, that wil automaticly move and rename files with specific characters or words in a file name. Unfortunatly i'm stuck, with the search function, too establish it. Can someone help me? For Example: filename: KQsect-XS-32.xml Search for 'XS-32', if XS-32 then rename to: XS-32.xml, then move to: X:\XS I'll hope you understand. Edited April 7, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
d4rk Posted April 7, 2008 Share Posted April 7, 2008 can't give a total help but FileFindFirstFile : show you the file name [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
rudi Posted April 7, 2008 Share Posted April 7, 2008 (edited) Hello.filename: KQsect-XS-32.xml1.) Search for 'XS-32', 2.) if XS-32 then rename to: XS-32.xml, 3.) then move to: X:\XS1.) As answered before filefindfirstfile() returns you the file name.1.a) for such a simple string search have a look at the function StringInStr()1. for more complex pattern search look at StringRegExp()2.) Use FileMove() to rename a file3.) FileCopy() will do what you want.Regards, Rudi. Edited April 7, 2008 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Triblade Posted April 7, 2008 Share Posted April 7, 2008 Combine the FileFindFirstFile from the above post with StringInStr (Search in Helpfile). StringInStr: Checks if a string contains a given substring. StringInStr ( "string", "substring" [, casesense [, occurrence]] )oÝ÷ ØZ襥©Ý²·)à'gßÛmzË^v+[ºÛ!¢é]ÂäÝ7êÇÈ]¸¬¶¯j¸nW°êÞÊ©ç^~)Þ¶¬yªÜGb¶Øb²å¢m+-¢ë¢Ø^®Ê.Ç»7Ý«¢+ØÀÌØíÍÉ¡¥ÈôÅÕ½ÐíèÀäÈíaLÀäÈìÅÕ½ÐììMÕͱ½Ü¡É((ìM¡½ÝÌÑ¡¥±¹µÌ½±°¥±ÌÑ¡Ðɽչ¸(ÀÌØíÍÉ ô¥±¥¹¥ÉÍÑ¥± ÀÌØíÍÉ¡¥ÈµÀìÅÕ½Ð쨸¨ÅÕ½Ðì¤ìMÉ ¥¸Ñ¡ÀÌØíÍÉ¡¥È¥ÉѽÉä((ì ¡¬¥Ñ¡ÍÉ ÝÌÍÕÍÍÕ°)%ÀÌØíÍÉ ô´ÄQ¡¸(5Í ½à À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðí9¼¥±Ì½¥Éѽɥ̵ѡѡÍÉ ÁÑÑɸÅÕ½Ðì¤(á¥Ð)¹%()]¡¥±Ä(ÀÌØí¥±ô¥±¥¹9áÑ¥± ÀÌØíÍÉ ¤(%ÉɽÈQ¡¸á¥Ñ1½½À($$(%MÑÉ¥¹%¹MÑÈ ÀÌØí¥±°ÅÕ½ÐíaL´ÌÈÅÕ½Ðì°È¤±ÐìÐìÀQ¡¸ìMÉ ½Èå½ÕÈáµÁ±ÑáÐ($%¥± ½Áä ÀÌØí¥±°ÅÕ½Ðí`èÀäÈíaLÀäÈíaL´ÌȹᵰÅÕ½Ðì°ä¤ì5½ÙÑ¡¥±¸IÑ¡¡±Á¥±½¸Ñ¡¥Ì½µµ¹¸äô ÉÑ¥É̹½ÙÉÝɥѥá¥ÍÑÌÌÌìÌÌì(%¹%($(í5Í ½à ÐÀ䨰ÅÕ½Ðí¥±èÅÕ½Ðì°ÀÌØí¥±¤ì¥±Ñ¡Ð¥Ì½Õ¹¥Ì¥ÍÁ±å¡É)]¹((ì ±½ÍÑ¡ÍÉ ¡¹±)¥± ±½Í ÀÌØíÍÉ ¤ My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) Thank you for the fast reply's! I have this code right now, and it doens't work.the test file I want too search and rename/replace is called 45XS-3254k.xmlI don't know how too combine it, because i'm new too auto IT.Right now It doens't work... searchdir = "C:\XS\" ; See use below here; Shows the filenames of all files that are found.$search = FileFindFirstFile($searchdir & "*XS-32*") ; Search in the $searchdir directory; Check if the search was successfulIf $search = -1 ThenMsgBox(0, "Error", "No files/directories matched the search pattern")ExitEndIfWhile 1$file = FileFindNextFile($search) If @error Then ExitLoopIf StringInStr($file, "XS-32", 2) <> 0 Then ; Search for your example textFileCopy($file, "X:\XS\XS-32.xml", 9) ; Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!!EndIf;MsgBox(4096, "File:", $file) ; File that is found is displayed hereWEnd; Close the search handleFileClose($search) Edited April 7, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 Ok. At filecopy, he creates the directory, but he is not copying the file... Link to comment Share on other sites More sharing options...
d4rk Posted April 7, 2008 Share Posted April 7, 2008 FileCopy($file & ".xml", "X:\XS\XS-32.xml", 9) [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) FileCopy($file & ".xml", "X:\XS\XS-32.xml", 9)I don't really understand, I have this line:If StringInStr($file, "XS-32", 2) <> 0 Then ; Search for your example text FileCopy($file, "H:\XS\XS-32.xml", 9)He is Creating the Dir on H: But he is not copying the file XS-32.xml from C:\XS in it. Edited April 7, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
d4rk Posted April 7, 2008 Share Posted April 7, 2008 yes, $file in the line "FileCopy($file, "H:\XS\XS-32.xml", 9)" just the file name with its extension , Ex: 123XS-32.xml , it isn't the "source" as the format of the filecopy() func, so you have to give it a the parent dir Ex : C:\dir\123XS-32.xml [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) I'm a little bit confused, I just can't get it working.If StringInStr($file, "XS-32", 2) <> 0 Then ; Search for your example text FileCopy($file & "XS-32.xml", "H:\XS\" , 9); Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!! EndIfI Don't see the problem Edited April 7, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
d4rk Posted April 7, 2008 Share Posted April 7, 2008 (edited) this's from the help file FileCopy ( "source", "dest" [, flag] )so you have to point out the source of the $file, run this script If StringInStr($file, "XS-32", 2) <> 0 Then; Search for your example text MsgBox(4096, "File:", $file); File that is found is displayed here EndIf the msbox will show the file name only, without it's directory, so the filecopy() can't work because it doesn't where to take the source to copy to Edited April 7, 2008 by d4rk [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 I'm sorry, but I don't get it Right...*sigh* He won't copy the dir anymore...$searchdir = "C:\XS\" ; See use below here; Shows the filenames of all files that are found.$search = FileFindFirstFile($searchdir & "*XS-32*" ) ; Search in the $searchdir directory; Check if the search was successfulIf $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitEndIfWhile 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, "C:\XS\XS-32", 2) <> 0 Then ; Search for your example text FileCopy($file & "C:\XS\", "H:\XS\" , 9); Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!! EndIf ;MsgBox(4096, "File:", $file) ; File that is found is displayed hereWEnd; Close the search handleFileClose($search) Link to comment Share on other sites More sharing options...
d4rk Posted April 7, 2008 Share Posted April 7, 2008 oh my god , please copy these code nad run it again $searchdir = "C:\XS\"; See use below here ; Shows the filenames of all files that are found. $search = FileFindFirstFile($searchdir & "*XS-32*" ); Search in the $searchdir directory ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, "C:\XS\XS-32", 2) <> 0 Then; Search for your example text FileCopy("C:\XS\" & $file, "H:\XS\" , 9); Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!! EndIf ;MsgBox(4096, "File:", $file); File that is found is displayed here WEnd ; Close the search handle FileClose($search) [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) I'm sorry. Ok, I have copied, the file, and replaced it , but it still, wo'nt work. it does nothing. Edited April 7, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
weaponx Posted April 7, 2008 Share Posted April 7, 2008 (edited) It shouldn't work either. This line is wrong: StringInStr($file, "C:\XS\XS-32", 2) FileFindNextFile doesn't return a full path so $file will never have "C:\XS\" on the front and thusly this search will always fail. Also you are only returning results matching *XS-32* from FileFindFirstFile() so why is this even necessary? Edited April 7, 2008 by weaponx Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 7, 2008 Author Share Posted April 7, 2008 (edited) Because I want charachter, specific searh in a file name ( specific log files in this case I want to rename and move automaticly ) Oke, changing that line works, thank you very much to all of you. Also I want to rename the files that where copied in H:\XS. I found the stringreplace command, but I don't know how too combine it with my code. Can anyone help? Situation: I want all the copied files in H:\XS to be renamed too: XS-tes.xml Edited April 8, 2008 by joopgoudvis Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 8, 2008 Author Share Posted April 8, 2008 -edited, double. Link to comment Share on other sites More sharing options...
d4rk Posted April 8, 2008 Share Posted April 8, 2008 Situation: I want all the copied files in H:\XS to be renamed too: XS-tes.xmlare you serious ? can you manually rename alls file in a folder with a same name and extension ? [quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys Link to comment Share on other sites More sharing options...
joopgoudvis Posted April 8, 2008 Author Share Posted April 8, 2008 are you serious ? can you manually rename alls file in a folder with a same name and extension ?No. I'm sorry for the miss understanding here. I will try too explain the situation:Everyday, I'll get 2 number of logfiles. These logfiles have a huge file name. in that filename, there is a word ( in this example XS-32) That is consistent everytime. After I purchase the logfiles, I must run them trough an application, this application accepts only the term 'XS-32'. So every time there are new logfiles (everyday) I have too manualy search the right logfile, adjust the file name too 'XS-32' and run that file trough the application.I want too automate it with AutoIT.The Thing I've been running into right now:I want to rename the files in the H:\XS Dir, too XS-32 instead of the huge filename by default. I've tried it with the string replace function, but it did'nt work.Again, Sorry for the misunderstanding, and for the bad posts in this topic. I will try too be more clear from now. ( I'm not used too type in english). Link to comment Share on other sites More sharing options...
weaponx Posted April 8, 2008 Share Posted April 8, 2008 You use FileMove() to rename files. 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