Remember Me
forgot your password?

AutoIt: How to copy a file's contents and paste using the clipboard

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 information, to use the Send() with a variable is used as follows:

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:

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:

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:

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:

printOutput2())

AutoIt: Copy File as in Explorer

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

FileCopy("C:file_to_copy.txt", "D:mydirfile_to_copy.txt")

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:mydirfile_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:

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:

FileCopy("C:tempd*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:

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.

Victor Kimura

AutoIt Tutorial, tips, guides. Learn AutoIt programming. Victor Kimura
Vista Tutorial Please view the original article to properly view the code and step-by-step snapshots:AutoIt: Copy & Paste, Copy File

Rate this Article: 0 / 5 stars - 0 vote(s)
Print Email Re-Publish

Add new Comment



Captcha
0
1. Torrie (15:28, 11.09.2009)
I am searching for a cliboard fo an arrest where do to look ?

  • Latest Programming Articles
  • More from Victor Kimura

How to Repair Java Errors and Errors that are Commonly Confused with Java

By: Amit Mehta | 02/12/2009
Let’s all be honest. When we think of the word "java," what usually comes to mind is either a steaming cup of coffee or the island in Indonesia. When referring to computers, Java means something else entirely. For those of us that have no clue what this "Java" is or does, here is the lowdown on Java errors, what they are, and how to fix them.

Build Service Oriented Composite Applications with new Book on Oracle SOA Suite 11g

By: Swati | 02/12/2009
Getting Started With Oracle SOA Suite 11g R1 is a new book from Packt that helps develop service-oriented composite application using the much anticipated Oracle SOA Suite 11g. Written by Oracle SOA Suite Product Management team members, this book walks the reader through the development of a services-oriented applications based on a real-life scenario.

Writing plugins for RDesktop

By: Apriorit Inc. | 01/12/2009
This article was mostly written for Linux developers. The article gives a method of writing out-of-process plugins to open source software – i.e., plugins that will work as a part of the software but will run in another process, so their code may stay closed.

ASP.Net Listview Databinding

By: pons_saravanan | 01/12/2009
Databind the ListView with database using ADO.Net datatable

Your mobile phone is too important not to have mobile antivirus software

By: Tom | 01/12/2009
Mobile phone antivirus software and mobile phone antispam software have become important and popular features to have on your mobile phone these days.

A reason to smile for All PHP Developers

By: Mahendra Sharma | 28/11/2009
The PHP developers have full right to smile today due to their choice of career as PHP programmers. This article is highlighting some key factors on how this language is bypassing all other in the website development world.

How to Solve the Registry Errors

By: janson | 27/11/2009
The Registry of Windows is the most important for the working of the computer system due to it stores valuable data which can cause serious loss in performance of the system. The registry files of Windows are set to save the configuration settings of Windows and they are spread around on the hard disk. To solve the errors of them was absolute a Herculean task.

Gravity Jack Software Studio is a new venture that is pushing the envelope in the mobile software development arena

By: Adam Chronister | 26/11/2009
Gravity Jack opened offices this month in Liberty Lake and is currently filing patents regarding a tightly-kept secret project that is expected to revolutionize the way people interact with mobile computing platforms such as Apple’s iPhone and Google’s Android.

Windbg Minidump Tutorial:Setting up & Reading Minidump Files

By: Victor Kimura | 07/07/2009 | Programming
Windgb Minidump tutorial to set up and read minidump files (.dmp). Setting Symbol File Path. Output of Windbg command. windbg.exe -z [file path to minidump file.dmp] -c !analyze -v.

Thunderbird Cannot Connect to Server-Download Email Problem

By: Victor Kimura | 07/07/2009 | Software
Thunderbird cannot connect to server problem. How to resolve the problem if you have trouble downloading email from the server and the hour glass figure keeps displaying. Could be related to a virus, or Norton attempting to scan the infected email or a process error of Thunderbird.

Javascript Validate Name Field

By: Victor Kimura | 07/07/2009 | Programming
Simple Javascript tutorial on validating a name field. Checks to see if there is a value in the name field with Javascript after the user submits a form.

AutoIt: How to copy a file's contents and paste using the clipboard

By: Victor Kimura | 19/06/2009 | Programming
AutoIt tutorial-How to copy text and paste it from the clipboard using variables. How to copy a file and its name to another directory.

AutoIt:Connect to Access Databases:mdb & accdb files

By: Victor Kimura | 15/06/2009 | Programming
AutoIt tutorial discussing how to connect to an Access 2007 and 2003 database. .mdb and .accdb file extensions connections are made. How to retrieve a single record and place a field's value into a variable.

IMAP Multiple Connections / Processes Problem:Site Down

By: Victor Kimura | 15/06/2009 | Networks
IMAP with multiple connections can cause problems and bring down your website. This could be due to multiple IMAP processes that linger. You need to kill these IMAP processes in the control panel.

Web Hosting Transfer Domain:Transferring Domain to Another Provider or Account

By: Victor Kimura | 11/06/2009 | Networks
How to transfer domains to another web hosting provider or to another web hosting account (with the same provider). Step-by-step instructions for transferring your domain safely.

Submit Your Articles Free: Signup
Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.07, 1, w1)