Sign in to follow this  
Followers 0
cutedog09

To select & copy a line from notepad

5 posts in this topic

I'm a newbie so pls help me...

I want to select & copy-paste one line at a time from txt document.So my problem is:

1)How to make AutoIt copy and paste one line at a time from a text file with/without it being open in Notepad?

2)how do i keep track of my position in the txt document ?(.ie. which line is to be copied next)

I'm new to scripting(2days B) ) but familiar with programming(C/C++)

Any help on this wud b appreciated..thanx in advance :o

(Thanx to Lxp :graduated: )

Share this post


Link to post
Share on other sites



I'm a newbie so pls help me...

I want to select & copy-paste one line at a time from txt document.So my problem is:

1)How to make AutoIt copy and paste one line at a time from a text file with/without it being open in Notepad?

2)how do i keep track of my position in the txt document ?(.ie. which line is to be copied next)

I'm new to scripting(2days B) ) but familiar with programming(C/C++)

Any help on this wud b appreciated..thanx in advance :o

(Thanx to Lxp :graduated: )

Lookup FileReadLine in the help file. Remember to look at the example.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

So what exactly do you want to do after each line?

This part of a script, read a file one line at a time and wrote it to another file, when it found the line I was looking for it edited the string and wrote it to the new file, then moved on and copied the rest of the original file to the new file. Then it deletes the original file and renames the temp file to the old name.

Maybe you can get some ideas from it?

$file = FileOpen($Path & "Messages\English\messages.txt", 0)
_FileCreate ( $Path & "Messages\English\Messages.tmp" )
$NewFile = FileOpen ( $Path & "Messages\English\Messages.tmp", 2 )

; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open Messages.txt")
        Exit
    EndIf

; Read in lines of text until the EOF is reached
    While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop

        $result = StringInStr($line, "IDS_PAPER_TYPE_MATTE  ""Matte""")
        If $Result =0 then
    ;do nothing until Filewriteline to copy original text  to tmp file  
        Else 
        $Line = @tab & "IDS_PAPER_TYPE_MATTE    ""Lustre"""
        Endif
        FileWriteLine ($NewFile, $Line)
    Wend
    
    FileClose ( $File )
    FileClose ( $NewFile )
    FileDelete ( $Path & "Messages\English\messages.txt" )
    FileMove($Path & "Messages\English\Messages.tmp", $Path & "Messages\English\Messages.txt")

Share this post


Link to post
Share on other sites

Perhaps you're after this. Simply change the first line to point to any existing text file.

Local Const $File = @ScriptDir & '\Lines.txt'

Global $Handle = FileOpen($File, 0)
If $Handle = -1 Then
    MsgBox(0x10, 'Error', 'Could not open the file:' & @LF & $File)
    Exit
EndIf

HotkeySet('^{RIGHT}', 'NextLine')
HotkeySet('{ESC}', 'Done')

NextLine()

While 1
    Sleep(0x7FFFFFFF)
WEnd

Func NextLine()
    Local $NextLine = FileReadLine($Handle)
    If @Error Then
        MsgBox(0x40, 'End of File', 'The end of the file has been reached.')
        Done()
    EndIf
    ClipPut($NextLine)
    TrayTip('Copied to Clipboard', $NextLine & @LF & @LF & 'Ctrl+Right: Next line' & @LF & 'Esc: Quit', 5, 1)
EndFunc

Func Done()
    FileClose($Handle)
    Exit
EndFunc

Share this post


Link to post
Share on other sites

WOW!!...my prob. solved!! :o ..special thanx to LxP and ChrisL for taking the trouble to post scripts..i wud surely analyse them further to learn more...and i'm also thankful to BigDod for showing me the way.

I feel good to b the part of this community B)

Share this post


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
Sign in to follow this  
Followers 0