Jump to content

Trying to 8 lines from txt file to another txt file


voidale
 Share

Recommended Posts

This one worked but the lines from from.txt, are 1 line over the to.txt gotta add enter?

and can you do it will delete the 8 that just copied from "from.txt" so if you repeat it the next 8 will be new lines

Not sure what you mean here but try this

$aText = StringRegExp(FileRead("from.txt"), "(?i)(.+)(?:\v)+", 3)
If NOT @Error Then
    $sStr = ""
    For $i = 0 To Ubound($aText) -1
        $sStr &= $aText[$i] & @CRLF
        If $i = 7 Then ExitLoop ;; Adjust the number of lines here >> Desired number of lines -1
    Next
    $hFile = FileOpen("to.txt", 2)
    FileWrite($hFile, StringStripWS($sStr, 2))
    FileClose($hFile)
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

well wow guys everyone thanks alot for the help

This code works perfect

#include <File.au3>  
Local $Sourcefile = "from.txt"
Local $destinationfile = "to.txt"
Local $aFileLines[9]


For $i = 1 To 8
    $read = FileReadLine($Sourcefile,$i)
    $aFileLines[$i] = $read
Next

For $x=1 To 8
    _FileWriteToLine($Sourcefile, 1, "", 1)
Next

For $i = 1 To 8
    FileWriteLine($destinationfile,$aFileLines[$i])
Next
Link to comment
Share on other sites

---- ORIGINAL CODE DELETED ----

Improved version:

#include <File.au3>

$countLines = _FileCountLines("to.txt")
While 1
    For $x = 1 To 8
        If $countLines = 0 Then
            ExitLoop 2
        EndIf
        $ReadLine=FileReadLine("to.txt", 1)
        _FileWriteToLine("to.txt", 1, "", 1)
        FileWriteLine("output.txt", $ReadLine)
        $countLines -= 1
    Next
    MsgBox(0, "Transfer Info", "8 lines transferred successfully." & @CRLF & "Click ok to continue.")
WEnd
MsgBox(0, "Finished", "Exact copy of original file completed" & @CRLF & "8 lines at a time.")

I'm not really sure what exactly you are trying to do, but maybe this helps.

Edited by czardas
Link to comment
Share on other sites

having hard time with ControlClick now this is the code

Run("File.exe")
WinWait("File", "File")
If Not WinActive("File", "File") Then WinActivate("file", "File")
ControlClick("File", "File", "Button4")

it opens the exe and takes a focus fine but it won't click Buttun4 (Got it using the info tool)

any ideas?

Edited by voidale
Link to comment
Share on other sites

having hard time with ControlClick now this is the code

Run("File.exe")
WinWait("File", "File")
If Not WinActive("File", "File") Then WinActivate("file", "File")
ControlClick("File", "File", "Button4")

it opens the exe and takes a focus fine but it won't click Buttun4 (Got it using the info tool)

any ideas?

still can't figure out how to make it work ;s
Link to comment
Share on other sites

Here is a function that does the move simply with error checking...

Just stick it in and it'll work.

Func Move_lines()
    Local $from = StringSplit(FileRead("from.txt"),@CRLF,1)
    For $i=1 To _lower(8,$from[0])
        FileWriteLine("to.txt",$from[$i])
    Next
    If $from[0]>8 Then
        FileDelete("from.txt")
        For $i=9 To $from[0]
            FileWriteLine("from.txt",$from[$i])
        Next
    Else
        FileWrite("from.txt","")
    EndIf
EndFunc

Func _lower($a,$b)
    If $a<$b Then Return $a
    Return $b
EndFunc

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Link to comment
Share on other sites

Sometimes ControlClick won't work, although it usually does on an unactivated app, so it surely should on an activated one.. Try a MouseClick at the right coords.. And post the InfoTool output too so it can be read by others here..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Here is the window info trying to get a click over button4

>>>> Window <<<<
Title:  Vista V1.3
Class:  WindowsForms10.window.8.app.0.378734a
Position:   90, 90
Size:   905, 589
Style:  0x16CF0000
ExStyle:    0x00050100
Handle: 0x00000000000106A8

>>>> Control <<<<
Class:  WindowsForms10.BUTTON.app.0.378734a
Instance:   3
ClassnameNN:    WindowsForms10.BUTTON.app.0.378734a3
Name:   Button4
Advanced (Class):   [NAME:Button4]
ID: 67282
Text:   SEND
Position:   684, 58
Size:   195, 55
ControlClick Coords:    57, 38
Style:  0x5601000B
ExStyle:    0x00000000
Handle: 0x00000000000106D2

>>>> Mouse <<<<
Position:   840, 222
Cursor ID:  0
Color:  0xD8D8D8

don't really find simple examples to use WinGetPos

this is what i got so far

$size = WinGetPos("[Vista V1.3]")
MsgBox(0, "Active window stats (x,y,width,height):", $size) (send a msg box with 0

MouseClick("left", $size, 1) this will be the correct cords?
Link to comment
Share on other sites

Here is the window info trying to get a click over button4

>>>> Window <<<<
Title:  Vista V1.3
Class:  WindowsForms10.window.8.app.0.378734a
Position:   90, 90
Size:   905, 589
Style:  0x16CF0000
ExStyle:    0x00050100
Handle: 0x00000000000106A8

>>>> Control <<<<
Class:  WindowsForms10.BUTTON.app.0.378734a
Instance:   3
ClassnameNN:    WindowsForms10.BUTTON.app.0.378734a3
Name:   Button4
Advanced (Class):   [NAME:Button4]
ID: 67282
Text:   SEND
Position:   684, 58
Size:   195, 55
ControlClick Coords:    57, 38
Style:  0x5601000B
ExStyle:    0x00000000
Handle: 0x00000000000106D2

>>>> Mouse <<<<
Position:   840, 222
Cursor ID:  0
Color:  0xD8D8D8

don't really find simple examples to use WinGetPos

this is what i got so far

$size = WinGetPos("[Vista V1.3]")
MsgBox(0, "Active window stats (x,y,width,height):", $size) (send a msg box with 0

MouseClick("left", $size, 1) this will be the correct cords?

Anyone?
Link to comment
Share on other sites

'Subscript used with non-Array variable' means your WinGetPos failed ...

Maybe you've specified the wrong Window title ?

>>>> Window <<<< Title: Vista V1.3 Class: WindowsForms10.window.8.app.0.378734a Position: 90, 90 Size: 905, 589 Style: 0x16CF0000 ExStyle: 0x00050100 Handle: 0x00000000000106A8

try

$size = WinGetPos("Vista V1.3")
; check for failure
If Not $size = 0 Then
 MouseClick("left", $size[0], $size[1])
Else
 MsgBox(0, "error", "WinGetPos Error !")
EndIf

HTH,

whim

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...