MarkMarkMark Posted April 28, 2005 Share Posted April 28, 2005 Hej guys, How can i rename allot of files in a folder in 1 time... can it be dong with the Stringreplace command? _mark. Link to comment Share on other sites More sharing options...
CyberSlug Posted April 28, 2005 Share Posted April 28, 2005 Use FileMove to rename files. See also FileFindFirstFile in the helpfile. FileMove($oldname, $newname) ;assuming the folder is the same for both paths, this is a rename Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
sandyd Posted April 28, 2005 Share Posted April 28, 2005 How do you want to rename them? By putting a number after them, or before or some other way perhaps. If its only a number before, you could use the dos rename command, do rename/? in a dos window for usage instructions. You can also use wildcards in your rename command. e.g. rename *.log *.txt or rename filename*.log otherfilename*.txt Hope this helps ----[ SandyD ]--- Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 (edited) Here is the thing: I have a list of files in my folder with like 500 files named something like this: pr9.234432.test.com back.txt.eml pr9.234532.test.com back.txt.eml pr9.231432.test.com back.txt.eml pr9.234432.test.com back.txt.eml pr9.234882.test.com back.txt.eml pr9.344432.test.com back.txt.eml pr9.211432.test.com back.txt.eml so now i want to rename all of them to: example: pr9.234234.txt pr9.234457.txt pr9.234871.txt i cant make it work in msdos.. AND in AUtoit :S and then i want to delete from every file the lines 1 untill 10... but i think i will figure that out myself Edited April 28, 2005 by MarkMarkMark Link to comment Share on other sites More sharing options...
CyberSlug Posted April 28, 2005 Share Posted April 28, 2005 Look at the FileFindFirstFile help file example, and replace the MsgBox(4096, "File:", $file) line with something like:$newName = StringReplace($file, ".test.com back.txt.eml", ".txt")FileMove($file, $newName)I STRONGLY RECOMMEND MAKING A BACKUP OF YOUR FILES BEFORE DOING THIS JUST IN CASE I MADE A TYPO Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 Tnx man, That working so fast / good. if i put something under $newName = StringReplace($file, ".test.com back.txt.eml", ".txt") FileMove($file, $newName) will it work then? because i want to delete from every file row 1 till 10... can i work with fileread or filewrite there? Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 Mmm, im told to convert those .txt's into .xls (microsoft excel) is there a handy (free) tool for this? i found ABC Amber CSV Converter but it only works with 1 txt at the time (omg) Link to comment Share on other sites More sharing options...
sandyd Posted April 28, 2005 Share Posted April 28, 2005 Excel can read .CSV files, and .CSV files are lines of fields, each seperated by a comma symbol. Note that if the field is a text field, it is best to put it inside enclosing quote sysmbols ("text here"). When you are deleting the first 10 lines, just convert to the csv format. If your stuck, posta few lines of the file and we can take it from there. ----[ SandyD ]--- Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 mm lol, it works when u rename "bla.txt" to "bla.xls" the inside of the textdocuments look something like this (sorry im not allowed to post the exact data) : 1000001010101#4asdasd sfsdf@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1000001010101#4asdasd sfsdf1000001010101#4asdasd sfsdf1000001010101#4asdasd sfsdf234234324234 sfsdf@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1000001010101#4asdasd sfsdf1000001010101#4asdasd sfsdf1000001010101#4asdasd sfsdf234234324234 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 name tekst1 date1 date2 detail1 all different data.. all 500 files look something like this. so i have to delete all the crap @ the top few lines (10 lines always) 2. Is it possible to put the "colums of text" in real excel collums, without putting a "," between al this? You guys are great.... -mark Link to comment Share on other sites More sharing options...
CyberSlug Posted April 28, 2005 Share Posted April 28, 2005 Take a look at the the FileWriteLine example in the helpfileHere's one very simple and inefficient way to remove the first 10 lines of a file:Put Dim $linecount = 0 at the top of the scriptThen replace the MsgBox(....) in the example with: $linecount = $linecount + 1 If $linecount > 10 Then Then FileWriteLine("outputFile.txt", $line) Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 (edited) Dim $linecount = 0 $search = FileFindFirstFile("*.*") ; 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 $linecount = $linecount + 1 If $linecount > 10 Then Then FileWriteLine("outputFile.txt", $line) WEnd FileClose($search) So this has got to work? Ps. om at home now.. cant test it... i'll post if it worked tommorrow.. thank u guys allot already... (K) Edited April 28, 2005 by MarkMarkMark Link to comment Share on other sites More sharing options...
CyberSlug Posted April 28, 2005 Share Posted April 28, 2005 (edited) No, you'll need something like this (still a bit inefficient since it doesn't use FileOpen): ; Shows the filenames of all files in the current directory $search = FileFindFirstFile("*.*") ; 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;done finding files MsgBox(4096, "File:", $file) ; Check if file opened for reading OK If $file = -1 Then ContinueLoop;couldn't open file; continue with next file ;throw away the first 10 lines For $i = 1 to 10 FileReadLine($file) Next While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop FileWriteLine($file & ".new.txt", $line) Wend WEnd ; Close the search handle FileClose($search) Edited April 28, 2005 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
MarkMarkMark Posted April 28, 2005 Author Share Posted April 28, 2005 Mm, this has to go out of it right?: MsgBox(4096, "File:", $file) 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