Jump to content

Help to copy content from a txt :(


Recommended Posts

I am trying to do something that I considered to be quite simple:open a .txt copy its content and then close it. However, I tried different ways as you will see in the codes that i attach but none of them work. In the first code it doesn't open the file and in the second it opens notepad but then it doesn't open the file that i want. Thanks for your help!!

Run("C:\Documents and Settings\Pablo\Mis documentos\TEST.txt")
Send("^!e")
Sleep(1000)
Send("^!c")
Sleep(1000)
WinClose("TEST")

Run("notepad.exe")
WinWaitActive("Sin título - Bloc de notas")
Send("^!a")
WinWaitActive("Abrir")
Send("TEST")
Sleep(1000)
Send("{ENTER}")
WinWaitActive("TEST")
Send("^!e")
Sleep(1000)
Send("^!c")
Sleep(1000)
WinClose("TEST")
Edited by Mithrandir
Link to comment
Share on other sites

Run() only works with executables (EXE, BAT, COM, or PIF). Use ShellExecute instead if you want to open a document directly.

Run('Notepad "C:\Documents and Settings\Pablo\Mis documentos\TEST.txt"')
; or
ShellExecute("C:\Documents and Settings\Pablo\Mis documentos\TEST.txt")

I use an English OS, so I can't confirm your keystrokes...

But, you're sending Control+Alt+[a/e/c].

In my case, it's either Alt for the menu, or Control for accelerators. Never both together.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

If your just trying to read the content it's FileRead()

$file = FileOpen("C:\Documents and Settings\Pablo\Mis documentos\TEST.txt", 0)

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

$fileContent = FileRead($file)

FileClose($file)


MsgBox(0,'',$fileContent)
Link to comment
Share on other sites

Thanks to you I have corrected my code :D :

Run('Notepad "C:\Documents and Settings\Pablo\Mis documentos\TEST.txt"')
WinWaitActive("TEST - Bloc de notas")
Send("^e")
Sleep(1000)
Send("^c")
Sleep(1000)
WinClose("TEST")

What I want to do is to paste this information in a post in this code:

Run('Notepad "C:\Documents and Settings\Pablo\Mis documentos\TEST.txt"')
WinWaitActive("TEST - Bloc de notas")
Send("^e")
Sleep(1000)
Send("^c")
Sleep(1000)
WinClose("TEST")
#include <IE.au3>
$oIE = _IECreate ("http://forums.linkbucks.com/newthread.php?do=newthread&f=12")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
$oQuery2 = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "username")
_IEFormElementSetValue ($oQuery2, "password")
_IEFormSubmit ($oForm)
Sleep(10000)
$oForm1 = _IEFormGetObjByName ($oIE, "vbform")
$oQuery3 = _IEFormElementGetObjByName ($oForm1, "subject")
$oQuery4 = _IEFormElementGetObjByName ($oForm1, "message")
_IEFormElementSetValue ($oQuery3, "my test")
_IEAction ($oQuery4, "paste");in this line a Internet explorer window pop ups asking wheter i want the page to access to my clipboard :P

This is the window that appears:

post-50235-1244752256_thumb.jpg

And this is the info from autoitwindow:

post-50235-1244752441_thumb.jpg

The thing is that i don't know whether to treat this window as a normal window or as an internet explorer window thus having to use _IEAttach

Link to comment
Share on other sites

It is an IE window

***NOT TESTED, based on you stuff

#include <IE.au3>

ClipPut(FileRead("C:\Documents and Settings\Pablo\Mis documentos\TEST.txt"))

$oIE = _IECreate ("http://forums.linkbucks.com/newthread.php?do=newthread&f=12")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
$oQuery2 = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "username")
_IEFormElementSetValue ($oQuery2, "password")
_IEFormSubmit ($oForm)
Sleep(10000)
$oForm1 = _IEFormGetObjByName ($oIE, "vbform")
$oQuery3 = _IEFormElementGetObjByName ($oForm1, "subject")
$oQuery4 = _IEFormElementGetObjByName ($oForm1, "message")
_IEFormElementSetValue ($oQuery3, "my test")
_IEFormElementSetValue ($oQuery4,  ClipGet())

8)

NEWHeader1.png

Link to comment
Share on other sites

It functioned!! You impress me Valuater :D I hadn't thought of that function (Clipget) It seems I have a 'macro-way-of-thinking' lol cause I tried to code the copy and paste and couldn't get around that window. Now I also have problems to logout but I think I cannot avoid the window, here it is what I have made:

#include <IE.au3>
$oIE = _IECreate ("http://forums.linkbucks.com/")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
$oQuery2 = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "username")
_IEFormElementSetValue ($oQuery2, "password")
_IEFormSubmit ($oForm)
Sleep(10000);I would prefer not having to rely on this :P
_IELinkClickByText ($oIE, "Log Out")
Sleep(10000);I would prefer not having to rely on this :P
Send("{ENTER}");i thought that it would function as the window is set to active by default :S

I decided to use windows controls as it is suggested in the help file cause in the autoit window info there isn't a control called "Internet Explorer_Server" :

Remarks
_IEAttach provides the "dialogbox" parameter to attach to modal and modeless dialogs created by the browser. It is important to note that not all dialogs created through browser interaction can be attached to and controlled in this way. Many of these dialogs are actually standard windows and can be controlled through the traditional AutoIt window functions. A reliable way to tell the difference between these types of windows is to use the "AutoIt Window Info" tool to examine it -- if the window contains a control called "Internet Explorer_Server" then you can attach to it with this function, if it does not it is a standard window and traditional AutoIt windows functions must be used to control it.

Here is the code:

#include <IE.au3>
$oIE = _IECreate ("http://forums.linkbucks.com/")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
$oQuery2 = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "username")
_IEFormElementSetValue ($oQuery2, "password")
_IEFormSubmit ($oForm)
Sleep(10000)
_IELinkClickByText ($oIE, "Log Out")
WinWaitActive("Windows Internet Explorer", "", 5)
Send("{ENTER}")
; In the line of WinWaitActive I also tried using _IEAction ($oIE2, "focus")
;and ControlClick("Windows Internet Explorer", "Aceptar", "1") just in case but I don't think this will function cause it's a normal window

Here is the window that appears:

post-50235-1244755034_thumb.jpg

and here the info of the window:

post-50235-1244755070_thumb.jpg

and here the info of the 'Aceptar' Button:

post-50235-1244755110_thumb.jpg

Edit: I tried using IEManagement functions and I had errors (maybe this confirms that I have to consider it as a normal window?):

#include <IE.au3>
$oIE = _IECreate ("http://forums.linkbucks.com/")
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 0)
$oQuery2 = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "username")
_IEFormElementSetValue ($oQuery2, "password")
_IEFormSubmit ($oForm)
Sleep(10000)
_IELinkClickByText ($oIE, "Log Out")
$oIE2 = _IEAttach ("Windows Internet Explorer", "dialogbox")
_IEAction ($oIE2, "focus")
ControlSend("Windows Internet Explorer", "Aceptar", 1, "{ENTER}")

>"C:\Archivos de programa\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Pablo\Escritorio\TEST PARA DESLOGUEARME 2.au3" /autoit3dir "C:\Archivos de programa\AutoIt3" /UserParams  
+>13:16:09 Starting AutoIt3Wrapper v.2.0.0.1    Environment(Language:0C0A  Keyboard:0000040A  OS:WIN_XP/Service Pack 3  CPU:X86 OS:X86)
>Running AU3Check (1.54.14.0)  from:C:\Archivos de programa\AutoIt3
+>13:16:09 AU3Check ended.rc:0
>Running:(3.3.0.0):C:\Archivos de programa\AutoIt3\autoit3.exe "C:\Documents and Settings\Pablo\Escritorio\TEST PARA DESLOGUEARME 2.au3"    
--> IE.au3 V2.4-0 Error from function _IEAction, $_IEStatus_InvalidObjectType
+>13:17:04 AutoIT3.exe ended.rc:0
+>13:17:05 AutoIt3Wrapper Finished
>Exit code: 0   Time: 57.401
Edited by Mithrandir
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...