All templates
Desktop AutomationBeginner
Copy Files
Robomotion•Updated 11 months ago

Overview
Copies every file from a source directory into a destination, with optional overwrite. Demonstrates how to enumerate files and drive file-system operations from a subflow.
Copy Files
Creating copies of files and folders is a fundamental ability of the Windows file system. Using the available file and folder nodes, you can automatically copy files and folders and effortlessly perform tasks such as taking backups.
What Copy Files can do
- Seed sources (
Core.Programming.Function) — resolvesmsg.fixtures_dirunder$Home$/templates/.../fixtures, setsmsg.files_to_copyto[source_a.txt, source_b.txt]andmsg.default_desttofixtures/dest. - Input Dialog (
Core.Dialog.InputBox) titledCopy files, messageSelect the folder to copy the file to.., defaultmsg.default_dest→msg.destination_folder. - Branch on cancel (
Core.Programming.Function,outputs: 2) — ifmsg.destination_folderis empty, short-circuit toCore.Flow.Stop; otherwise proceed. - Create destination (
Core.FileSystem.Create,optType: directory,continueOnError: true) againstmsg.destination_folder, thenCore.Flow.GoTointoLoop Start. - Iterate (
Core.Programming.ForEach) overmsg.files_to_copy→msg.current_file,msg.current_index. - Build destination (
Core.Programming.Function) — extracts the basename ofmsg.current_fileand setsmsg.dest_path = msg.destination_folder + '\\' + basename. - Copy (
Core.FileSystem.Copy,continueOnError: true) frommsg.current_filetomsg.dest_path, thenCore.Flow.GoToback toLoop Startuntil the iterator exits and hitsCore.Flow.Stop.
Behind the scenes
continueOnError: trueonCore.FileSystem.Createlets the flow proceed when the destination directory already exists, and onCore.FileSystem.Copyit keeps the loop running if a single file fails to copy.- The loop is driven by a
Core.Flow.Label+Core.Flow.GoTopair wrapped aroundCore.Programming.ForEachso the per-file copy steps live on a separate wire and re-enter the iterator cleanly. - Destination path is built by scanning for the last
/or\\so the flow works with fixtures written using either separator.
More desktop automation templates
See all 17 →- Every customer from a CSVThe Windows Recorder's customer task run for every row of a CSV file, each typed value replaced by the row's field, with a Catch that logs a row the app will not take and goes on with the next.
- Putting it togetherOne flow over three systems. Headless Chrome reads today's web orders from Acme ERP Web, the finance system is asked about each customer over Remote Desktop, and the orders with nothing overdue are entered into Acme ERP for Windows, line by line, with a report at the end.
- Reading from a Java applicationA flow that signs in to Acme ERP (Java Edition), reads a customer's credit limit and the fasteners in the product table, works out how many boxes of each the limit covers, and writes the answer to a CSV file.
- Reading over Remote DesktopA flow that logs on to Acme ERP over Remote Desktop, reads the outstanding and overdue totals off the Invoices screen with OCR, each anchored to its label, and writes the overdue share to a CSV file.
- Slow sessionsA flow recorded on a good Remote Desktop session that logs on and updates a customer's email, phone and notes in Acme ERP, and still gets every value right on a slow session that loses keystrokes.
- Windows dialogs and gridsA flow that signs in to Acme ERP for Windows, waits for its orders grid, reads it with Get Table Data, exports the orders on hold through the Save As dialog, and closes the app answering its "Save changes?" question.