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:
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".
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) ;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:
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) ;get value of table's field by index number MsgBox(0, "test2", ClipGet())
Now to execute the function all you need to type is:
If you wish to copy a file as you would in Explorer then use the FileCopy function:
The format to use this function is:
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:
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:
Note that you cannot have have more than one wildcard in the filename and extension. So this will NOT work:
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:
will copy all files with the extension 'txt' as well any extension as 'txt*'. So extension 'txt1', 'txt2', 'txt3' will also by copied.