All templates
Desktop AutomationBeginner
Copy Files
Robomotion•Updated 6 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.