How to Copy a Files Contents and Paste in AutoIT using Clipboard

0
503
copy Large file
copy Large file
Spread the love

copy Large file
copy Large file

In this post, I will tell on how to quickly duplicate and paste massive quantities of textual content into fields once we get it from other source like database. The idea inception came from the problem when I was trying to automate a JNLP based application.The problem with sendKeys was, it was taking huge time to send a large text.This post talks about How to Copy a Large file in AutoIT.

As usual I was looking for a solution in google as well as stackoverflow to resolve this issue. Stackoverflow showed a way. They suggested to try AutoIT. I checked AutoIT documentation. The documentation made my job easy. Even the similar problem was mentioned in superuser forum.

As per Superuser forum:

AutoIt is a freeware Basic-like scripting language. Among its tricks, it can send fake keypresses to another program. This means that in principle, you could write a script that opens SQL Developer, waits for it to wake up, opens the right window, and does batches of those insert commands with a timed delay in between to give Developer a chance to catch up and empty the keyboard queue.

You can do some similar tricks with VBScript and the Windows Scripting Host, which you should already have, but I found AutoIt easier. I use it to automate a few jobs that would be a pain otherwise.

I still agree with Paul, though – it should be possible to load and run that script directly in SQL Developer. If you’re trying to avoid learning how for the moment, you’ll end up doing much more work learning other things to avoid it.

READ  What is Static Testing? Learn Static Testing Quickly

Another popular forum stackexchange also has the similar problem listed.

As per stackexchange:

AutoIt is a script language which allow you to automate the Windows’s user interface, and then to by-pass your security restriction.

To cover your needs AutoIt provides basic file access function (like you did it in Python I think) to read your .txt files’ content. Then with its Windows gui’s automation you can write the content into your Excell file (I recommend to use key trigger instead of mouse one’s) like a human would do it.

It’s a programming script language, so it’s very powerful, but it could be complicated for an uninitiated public, but you seem to be comfortable with programmation. Actually a macro recorder is provided, very useful for learning it.

AutoIt is well known for the large amount of game bots created with it. Personally I used it for automating text copy/paste and sending it through the network.

At this point, I was convinced that my issue can be resolved via AutoIT. I started learning the AutoIT codes. Few AutoIT forum post also suggested the solution. Please refer the AutoIT forum posts here:

Below are the consolidated effort I learned from all these forums:How to Copy a Large file in AutoIT.

The Syntax of Send() function is as follows:

Send($variable, 1)

Where parameter (i.e. flag) ‘1’ in the function indicates data is sent raw. The default is ‘0’ which is outlined as “Textual content incorporates special figures like + and ! to indicate Shift and ALT crucial-presses”.

AutoIt: ClipPut(), Positioning Contents to Clipboard

Nonetheless, this definitely is not the most productive technique to deliver large bodies of text to, say, notepad or to a form’s fields. The steps are as follows:

  1. Fetch the data.
  2. Put in the variable.
  3. Call the below function.
Func printOutput()
Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) 'get benefit of table's area by index 
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Ship("^v")
EndFunc

The ClipPut perform locations the textual content in our clipboard. Then all we want to do is Deliver() the keys Manage+v as:

send("^v")

AutoIt: ClipGet(), Get Contents of Clipboard

I attempted to use the ClipGet purpose however, this did not work for me. ClipGet functionality does return the worth when using the MsgBox function. So with MsgBox() this performs:

Func printOutput()
Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) 'get value of table's discipline by index 
MsgBox(, "myTest2", ClipGet())

Now to execute the operate all we will need to do is:

printOutput())

AutoIt: copy File as in Explorer

If you desire to duplicate a file as you would in Explorer then use the FileCopy perform:

FileCopy("C:\file_to_copy.txt", "D:\mydir\file_to_duplicate.txt")

The structure to use this perform is:

FileCopy ( "resource", "dest" [, flag] )

There are a number of flags that you can use with the FileCopy purpose:

[optional] this flag is a mix or a person of the next:

0= (default) do not overwrite present data files

1 = overwrite current files

8 = Produce spot listing construction if it doesn’t exist.

If we want to mix the flags then add the values with each other. In other terms, if we desire to overwrite an existing file in the desired destination and look at if the desired destination directory exists or not and if it does not then build the directory, then would use ‘9’ as the flag.

READ  Impact of Artificial Intelligence in Everyday Life

So the flag would be applied as:

FileCopy("C:\file_to_duplicate.txt", "D:\mydir\file_to_copy.txt", 9)

You can use wildcards in copying files these kinds of as ‘*’ which denotes zero or additional figures and ‘?’ which denotes zero or 1 character. So if you wished to duplicate all information in the temp directory (i.e. C:\temp) and then duplicate them to another directory you would use the pursuing code:

FileCopy("C:\temp*.*", "D:\mydir")

Be aware that you can not have have much more than just one wildcard in the filename and extension. So this will NOT get the job done:

FileCopy("C:\tempd*g?.*", "D:\mydir")

You would want to use regular expressions to accomplish this a lot more advanced job.

An additional be aware that applies specially the extension is matches will be manufactured for the very first 3 people of the extension. In other words and phrases, this:

FileCopy("C:\temp*.txt", "D:\mydir")

will copy all information with the extension ‘txt’ as well any extension as ‘txt*’. So extension ‘txt1’, ‘txt2’, ‘txt3’ will also by copied.


Spread the love
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here