Jump to content

Text file copy line


Recommended Posts

Ok I have a little problem, I know this is a primitive way to do a copy and paste and couldnt find anything in the functions that would do this better. The problem is that when it goes through the sets it only copies 1 of 2 times running it which doesnt help when it needs to copy and paste everything in the first time for what i want it to do. If you guys have any Suggestions please let me know how i can do this better. Thanks in advance!

$clipboard = ClipGet()

WinActivate("textfile.txt - Notepad")
    Send("{DOWN}")
    Send("{SHIFTDOWN}" & "{END}")
    Send("{SHIFTUP}")
    Send("{CTRLDOWN}" & "{C}")
    Send("{CTRLUP}")
    Send("{HOME}")
    
MsgBox(0, "Clipboard contains:", $clipboard)
Link to comment
Share on other sites

  • Moderators

Is there a reason that you couldn't read the file into an array?

#include <file.au3>

Global $aArray
Global $sTxtFile = "C:\textfile.txt"

If Not _FileReadToArray($sTxtFile, $aArray) Then
    MsgBox(4096, "Error", "Error reading file to Array     error:" & @error)
    Exit
EndIf

For $iLine = 1 To $aArray[0]
    MsgBox(0, "Line:" & $iLine, $aArray[$iLine])
Next
Link to comment
Share on other sites

Is there a reason that you couldn't read the file into an array?

#include <file.au3>

Global $aArray
Global $sTxtFile = "C:\textfile.txt"

If Not _FileReadToArray($sTxtFile, $aArray) Then
    MsgBox(4096, "Error", "Error reading file to Array     error:" & @error)
    Exit
EndIf

For $iLine = 1 To $aArray[0]
    MsgBox(0, "Line:" & $iLine, $aArray[$iLine])
Next
Hate to say it but I am a novice to arrays and do not know how to use all the functions yet. Arrays should be explained in the help file right?
Link to comment
Share on other sites

Ok I have a little problem, I know this is a primitive way to do a copy and paste and couldnt find anything in the functions that would do this better. The problem is that when it goes through the sets it only copies 1 of 2 times running it which doesnt help when it needs to copy and paste everything in the first time for what i want it to do. If you guys have any Suggestions please let me know how i can do this better. Thanks in advance!

$clipboard = ClipGet()

WinActivate("textfile.txt - Notepad")
    Send("{DOWN}")
    Send("{SHIFTDOWN}" & "{END}")
    Send("{SHIFTUP}")
    Send("{CTRLDOWN}" & "{C}")
    Send("{CTRLUP}")
    Send("{HOME}")
    
MsgBox(0, "Clipboard contains:", $clipboard)
You can interact directly with Notepad's Edit1 control, for example:
Global $hNotepad = WinGetHandle("textfile.txt - Notepad", ""); Get handle to window
Global $clipboard = ClipGet(); Get clipboard contents
    
; Replace the contents
ControlSetText($hNotepad, "", "Edit1", $clipboard)

; Append the contents
$sCurrentText = ControlGetText($hNotepad, "", "Edit1")
ControlSetText($hNotepad, "", "Edit1", $sCurrentText & @CRLF & $clipboard)

Much more complicated operations are possible, with a little learning of the functions.

Send()'ing raw keystrokes is not required, and is much less reliable.

:unsure:

P.S. Or, you could ignore Notepad altogether and work directly on the file, as big_daddy demonstrated before I got my post typed!

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Both are very nice examples! Thanks, I will read up on the arrays and others.

Just one is there any other functions that would allow you to communicate with a website: example buttons, text boxes, etc.?

This isnt going to be a spammer or anything just trying to make a program that checks sites then posts them in a database, kind of like a crawler or something.

Edited by Mutebox
Link to comment
Share on other sites

  • 8 years later...
On 3/22/2009 at 3:41 AM, Mutebox said:

 

Hate to say it but I am a novice to arrays and do not know how to use all the functions yet. Arrays should be explained in the help file right?

Hi, how do i search for a line based on a particular key word ?.. eg ; i have a text file of format (as shown in attachment), my input to the script would be 0017-0008 and the highlighted are to be copied to a variable 

input.png

Link to comment
Share on other sites

This post is over nearly 9 years old, and the user hasn't been here since this thread. Do you really think he's going to answer you?

 

Start a new thread

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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