Jump to content

Recommended Posts

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 post
Share on other sites

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 by MarkMarkMark
Link to post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

Take a look at the the FileWriteLine example in the helpfile

Here'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 script

Then 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 post
Share on other sites

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 by MarkMarkMark
Link to post
Share on other sites

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 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 post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...