Jump to content

Use FileReadLine in clipboard


Go to solution Solved by ioa747,

Recommended Posts

Posted

Hello,

Im new to autoit script and Im strucking with using Clipput from texts from a textdocument for line by line

FileRead are easier to use just need to use Clipput(FileRead($filename), but FileReadLine are too way complicated
I have checked severals thread but still cant find the right topic for my issue:

local $file="example.txt"

Func adresse()

For $i = 0 to 3 Step 1

     Clipput(FileReadLine($file)

   Send("v")

Next

Can someone put it example?

 

Thanks in advanced

 

Posted

Hello,

what´s mean :

local $tmp=""

should I put file adresse or what should come between?

Tried and still the clipput didnt work with the lines in files directed.

Thanks in advanced

Posted (edited)
local $tmp=""

it defines the $tmp variable as local (i started writing your script as a function, but then i thought, for demonstration purposes, to remove the function and have left it there.)

The script works, but it pastes the code anywhere it can. it reads 3 lines from the "example.txt". The example.txt needs to be in the same path where your script is.

If it does not work, it may be because there is nothing that it can paste into. To test it, start the script then open the notepad and paste the clipboard content manually. 

Edited by Dan_555

Some of my script sourcecode

Posted

 

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

Example()

Func Example()

    ; C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
    Local $sFilePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "\SciTE\Koda\history.txt"

    ; string to hold the lines
    Local $iLines = "1;4;10;25;39;50;63;70;75;104;113;128"

    ; convert to array for more convenient handling
    $iLines = StringSplit($iLines, ";")

    ; variable to hold the text from lines
    Local $sTXT = ""

    ; Read the lines 1;4;10;25;39;50;63;70;75;104;113;128
    ; of the file  C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
    ; to $sTXT
    For $i = 1 To $iLines[0]
        $sTXT &= "Line (" & $iLines[$i] & ") From ClipBoard: " & FileReadLine($sFilePath, $iLines[$i]) & @CRLF
    Next

    ;Writes text to the clipboard.
    ClipPut($sTXT)

    ; give some time
    Sleep(50)

    ; Run Notepad
    Run("notepad.exe")

    ; Wait max 3 seconds for the Notepad window to appear.
    Local $hNotePad = WinWait("[CLASS:Notepad]", "", 3)
    If WinActivate($hNotePad) Then
        ; paste
        Send("^v")
    EndIf

EndFunc   ;==>Example

 

I know that I know nothing

Posted
On 9/23/2023 at 4:15 PM, Dan_555 said:
local $tmp=""

it defines the $tmp variable as local (i started writing your script as a function, but then i thought, for demonstration purposes, to remove the function and have left it there.)

The script works, but it pastes the code anywhere it can. it reads 3 lines from the "example.txt". The example.txt needs to be in the same path where your script is.

If it does not work, it may be because there is nothing that it can paste into. To test it, start the script then open the notepad and paste the clipboard content manually. 

I tried with your code. The variable I put in $tmp= 5 and it put only clipboard 5 and not from the textdocument I sent.

 

On 9/23/2023 at 5:16 PM, ioa747 said:

 

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

Example()

Func Example()

    ; C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
    Local $sFilePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "\SciTE\Koda\history.txt"

    ; string to hold the lines
    Local $iLines = "1;4;10;25;39;50;63;70;75;104;113;128"

    ; convert to array for more convenient handling
    $iLines = StringSplit($iLines, ";")

    ; variable to hold the text from lines
    Local $sTXT = ""

    ; Read the lines 1;4;10;25;39;50;63;70;75;104;113;128
    ; of the file  C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
    ; to $sTXT
    For $i = 1 To $iLines[0]
        $sTXT &= "Line (" & $iLines[$i] & ") From ClipBoard: " & FileReadLine($sFilePath, $iLines[$i]) & @CRLF
    Next

    ;Writes text to the clipboard.
    ClipPut($sTXT)

    ; give some time
    Sleep(50)

    ; Run Notepad
    Run("notepad.exe")

    ; Wait max 3 seconds for the Notepad window to appear.
    Local $hNotePad = WinWait("[CLASS:Notepad]", "", 3)
    If WinActivate($hNotePad) Then
        ; paste
        Send("^v")
    EndIf

EndFunc   ;==>Example

 

I tried the code and it paste on the  notbook following results:


Line (1) From (ClipBoard: Release 1.7.3.0 build 252 (2010-07-30)
Line (4) From (ClipBoard: Beta 1.7.2.9 build 250 RC2 (2010-06-29)
Line (10) From (ClipBoard: Beta 1.7.2.8 build 247 RC1 (2010-04-15)
Line (25) From (ClipBoard: Beta 1.7.2.7 build 241 (2010-03-25)
Line (39) From (ClipBoard: Beta 1.7.2.6 build 229 (2010-03-15)
Line (50) From (ClipBoard: Beta 1.7.2.5 build 222 (2010-03-02)
Line (63) From (ClipBoard: Beta 1.7.2.4 build 214 (2010-02-18)
Line (70) From (ClipBoard: Beta 1.7.2.3 build 207 (2010-02-11)
Line (75) From (ClipBoard: Beta 1.7.2.2 build 204 (2010-02-04)
Line (104) From (ClipBoard: Beta 1.7.2.1 build 191 (2009-07-09)
Line (113) From (ClipBoard: Release 1.7.2.0 build 180 (2009-06-27)
Line (128) From (ClipBoard: Release 1.7.1.0 (2009-04-27)

It didnt paste the lines from the textfile I navigated.

Thanks in advanced

Posted

what you posted is my script, which reads lines  1;4;10;25;39;50;63;70;75;104;113;128  
from the file  C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
which is an example, that you should modify according to your needs
where is yours script ?

I know that I know nothing

Posted (edited)
3 hours ago, Lakers said:

I tried with your code. The variable I put in $tmp= 5 and it put only clipboard 5 and not from the textdocument I sent.

The code is in he 3rd post of this thread.

My second post explains your question. If you remember, you asked:

Quote

what´s mean :

local $tmp=""

and i gave you the explanation. 

As you can see:
 

For $i = 1 to 3 Step 1
     $tmp=$tmp & FileReadLine($file, $i) & @crlf
Next

is the correct usage of the variable $tmp.

Edited by Dan_555

Some of my script sourcecode

Posted
15 hours ago, Dan_555 said:

The code is in he 3rd post of this thread.

My second post explains your question. If you remember, you asked:

and i gave you the explanation. 

As you can see:
 

For $i = 1 to 3 Step 1
     $tmp=$tmp & FileReadLine($file, $i) & @crlf
Next

is the correct usage of the variable $tmp.

I get it. Thanks for your information.

How can I put it automatic for each turn the FileReadLine increase by x lines?

For example: The first time it will read line 1+2. Next time it will read 3+4 and so on?

Thanks in advanced.

17 hours ago, ioa747 said:

what you posted is my script, which reads lines  1;4;10;25;39;50;63;70;75;104;113;128  
from the file  C:\Program Files (x86)\AutoIt3\SciTE\Koda\history.txt
which is an example, that you should modify according to your needs
where is yours script ?

Thanks for your coding. I have replaced your file directory to my desired file directory. Still no success. The Clipboard for FileReadLine remains blank. 

Quote


Func Example()

    ; C:\Users\max\Downloads\test.txt
    Local $sFilePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "C:\Users\max\Downloads\test.txt"

    ; string to hold the lines
    Local $iLines = "1;4;10;25;39;50;63;70;75;104;113;128"

    ; convert to array for more convenient handling
    $iLines = StringSplit($iLines, ";")

    ; variable to hold the text from lines
    Local $sTXT = ""

    ; Read the lines 1;4;10;25;39;50;63;70;75;104;113;128
    ; of the file  C:\Users\max\Downloads\test.txt
    ; to $sTXT
    For $i = 1 To $iLines[0]
        $sTXT &= "Line (" & $iLines[$i] & ") From (ClipBoard: " & FileReadLine($sFilePath, $iLines[$i]) & @CRLF
    Next

    ;Writes text to the clipboard.
    ClipPut($sTXT)

    ; give some time
    Sleep(50)

    ; Run Notepad
    Run("notepad.exe")

    ; Wait max 3 seconds for the Notepad window to appear.
    Local $hNotePad = WinWait("[CLASS:Notepad]", "", 3)
    If WinActivate($hNotePad) Then
        ; paste
        Send("^v")
    EndIf

EndFunc   ;==>Example

Posted (edited)

change this
Local $sFilePath = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "C:\Users\max\Downloads\test.txt"


with this
Local $sFilePath =  "C:\Users\max\Downloads\test.txt"

 

PS: and please use code tags when you post code on forum, it's more easy to read

Edited by ioa747

I know that I know nothing

Posted

Hello,
I still need help on the coding.

How can I turn this into a Func and 

How can I put the variable increaase for each turn the FileReadLine by x lines?

For example: The first running time it will read line 1+2. Next loop it will read lines 3+4 and so on?

Thanks in advanced. Wishing everyone reading a great coding day.
 

  • Solution
Posted

 

Example()

Func Example()
    Local $sTxtFile = "C:\Users\max\Downloads\test.txt"
    Run("notepad.exe") ; Run Notepad
    Local $hNotePad = WinWait("[CLASS:Notepad]", "", 3)
    If WinActivate($hNotePad) Then
        For $i = 1 To 5
            _GetLinesToClip($sTxtFile)
            Send("^v")
            ;give time to see result
            Sleep(2000)
        Next
    EndIf
EndFunc   ;==>Example
;----------------------------------------------------------------------------------------
Func _GetLinesToClip($sFilePath, $LineCnt = 2)
    Local Static $iLines = 0
    Local $sTXT = ""
    For $i = 1 To $LineCnt
        $iLines += 1
        $sTXT &= "Line (" & $iLines & ") " & FileReadLine($sFilePath, $iLines) & @CRLF
    Next
    ClipPut($sTXT)
    Sleep(50)
EndFunc   ;==>_GetLinesToClip
;----------------------------------------------------------------------------------------

 

I know that I know nothing

Posted
local $file="example.txt"
local $tmp=""

For $i = 1 to 3 Step 1
     $tmp=$tmp & FileReadLine($file, $i) & @crlf
Next

Clipput($tmp)
Send("^v")

How can I put this into a func with my desired requirements above?

" How can I turn this into a Func and 

How can I put the variable increaase for each turn the FileReadLine by x lines?

For example: The first running time it will read line 1+2. Next loop it will read lines 3+4 and so on?"

 

Thanks in advanced!!!

Posted

I don't understand what you want, everything you ask is already ready, you just have to learn to use it.
After reading the two lines from the text file, what do you do next?

I know that I know nothing

Posted

I´m working on the coding from @Dan_555 It should be put in a func and for each turn the variable of reading line increse by x times. If you can help me with thtat code it will be very helpful. Thanks

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...