Tutorial Ref.com

AutoIt:Copy File Contents & Paste from Clipboard, Copy File & its Name to Directory

In this tutorial I show how to quickly copy and paste large amounts of text into fields of a form after retrieving the data from a database table. This is a recent problem that I wished to resolve since simply sending the variable's contents into a field takes time if you use the Send() and the contents of the variable contains a large amount of text. Just for your informaiton, to use the Send() with a variable is used as follows:

1
send($variable, 1)

You need the second parameter (i.e. flag) '1' in the function. The flag '1' means data is sent raw. The default is '0' which is defined as "Text contains special characters like + and ! to indicate SHIFT and ALT key-presses".

AutoIt: ClipPut(), Placing Contents to Clipboard

However, this really is not the most efficient method to send large bodies of text to, say, notepad or to a form's fields. Once you retrieve your data and place this data in a variable then all you need to do is the following:

1
2
3
4
5
6
7
Func printOutput2()
Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) ;get value of table's field by index number
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("^v")
EndFunc

The ClipPut function places the text within your clipboard. Then all you need to do is Send() the keys Control+v as:

1
send("^v")

AutoIt: ClipGet(), Get Contents of Clipboard

I attempted to use the ClipGet function; however, this didn't work for me. ClipGet function does return the value when usiing the MsgBox function. So with MsgBox() this works:

1
2
3
4
Func printOutput2()
Local $fTest
$fTest = ClipPut($outputArrayRS[0][2]) ;get value of table's field by index number
MsgBox(0, "test2", ClipGet())

Now to execute the function all you need to type is:

1
printOutput2())

AutoIt: Copy File as in Explorer

If you wish to copy a file as you would in Explorer then use the FileCopy function:

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

The format to use this function is:

1
FileCopy ( "source", "dest" [, flag] )

There are a few flags that you can use with the FileCopy function:

[optional] this flag is a combination or one of the following:
0 = (default) do not overwrite existing files
1 = overwrite existing files
8 = Create destination directory structure if it doesn't exist.

If you wish to combine the flags then add the values together. In other words, if you wish to overwrite an exiting file in the destination and check if the destination directory exists or not and if it does not then create the directory, then would use '9' as the flag.

So the flag would be used as:

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

You can use wildcards in copying files such as '*' which denotes zero or more characters and '?' which denotes zero or one character. So if you wished to copy all files in the temp directory (i.e. C:\temp\) and then copy them to another directory you would use the following code:

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

Note that you cannot have have more than one wildcard in the filename and extension. So this will NOT work:

1
FileCopy("C:\temp\d*g?.*", "D:\mydir\")

You would need to use regular expressions to accomplish this more complex task.

Another note that applies specifically the extension is matches will be made for the first 3 characters of the extension. In other words, this:

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

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

I found this resolves the problem of submitting to websites that partially use Javascript in its form. Websites that use Javascript makes it difficult to submit to forms with PHP's cURL functions - as far as I know anyway. This does have it's drawbacks in that I needed to use mouse movements to submit the form and, thus far, the procedure is only a partial submission.

TutorialRef.com - tutorials, guides, how-tos, helps