All templates
Desktop AutomationBeginner
Add Datetime to File Names
Robomotion•Updated 6 months ago

Overview
Renames every file in a directory by appending the current date to its name. A quick way to version artefacts, snapshots, or export batches.
Add Datetime to File Names
Managing locally saved files can be time-consuming for most home and business desktop users. Automate any file-system-related task, such as renaming files, using Robomotion's files and folders nodes.
What Add Datetime to File Names can do
- Build default folder (
Core.Programming.Function) →msg.default_folder = $Home$/templates/.../fixtures. - Input Dialog (
Core.Dialog.InputBox) titledAdd datetime to file names, defaultmsg.default_folder→msg.selected_folder. - Branch on cancel (
Core.Programming.Function,outputs: 2) — empty input short-circuits toCore.Flow.Stop. - List folder (
Core.FileSystem.List,optAbsolutePath: true,optSize: true,optIsDir: true,optCreateTime: true,optTop: 0) →msg.files_to_rename, thenCore.Flow.GoTointoLoop Start. - Iterate (
Core.Programming.ForEach) overmsg.files_to_rename→msg.current_file. - Skip dirs and stamped (
Core.Programming.Function,outputs: 2) — directories and names already matching-YYYYMMDD.are routed toLoop Back Skip; otherwise setsmsg.source_path = current_file.Nameandmsg.create_time = current_file.CreateTime. - Format stamp (
Robomotion.DateTime.Format, custom out layout20060102) frommsg.create_time→msg.stamp. - Build new path (
Core.Programming.Function) — splits on the last/or\\and last.to producemsg.target_path = <dir>\\<stem>-<stamp><ext>. - Check collision (
Core.FileSystem.PathExists) onmsg.target_path→msg.target_exists; if true, a Function routes toLoop Back Skip, otherwiseCore.FileSystem.Move(continueOnError: true) renames source to target andCore.Flow.GoTore-enters the loop. - When the iterator exits, flow reaches
Core.Flow.Stop.
Behind the scenes
Core.FileSystem.ListwithoptCreateTime: trueprovidesCreateTimeper entry, which is what drives the stamp — modification time and wall-clockNoware intentionally not used so the name reflects the file's own origin.- The stamp is placed before the extension (
name-YYYYMMDD.ext), which requires splitting on the last.; files with no extension just getname-YYYYMMDD. - Name collisions are handled silently:
Core.FileSystem.PathExistsplus a branch send already-taken targets to the skip label, so the original file is left untouched with no error. - The
-YYYYMMDD.regex guard prevents repeat runs from re-stamping already-processed files.