All templates
Desktop AutomationIntermediate
Delete Files of Specific Size Range
Robomotion•Updated 6 months ago

Overview
Scans a directory and deletes files whose size falls inside a min/max range. Useful for pruning oversized logs or clearing tiny scratch files.
Delete Files of Specific Size Range
Managing considerable amounts of files can be inefficient when performed by manual labor. Robomotion enables you to filter and handle files and manage your machine's storage automatically.
What Delete Files of Specific Size Range can do
- Seed fixtures (
Core.Programming.Function+ threeCore.FileSystem.WriteFile) — dropssmall.txt(200 B),medium.txt(3 KB) andlarge.txt(20 KB) undermsg.fixtures_dirso the template is runnable out of the box. - Input Dialog (
Core.Dialog.InputBox) titledDelete files by size range, promptWhat is the minimum size of the files you want to delete? (in KB), default1→msg.min_size_text. - Input Dialog (
Core.Dialog.InputBox) with promptWhat is the maximum size of the files you want to delete? (in KB), default10→msg.max_size_text. - Input Dialog (
Core.Dialog.InputBox) with promptPlease select the folder to delete files from...., defaultmsg.fixtures_dir→msg.selected_folder. - Parse inputs (
Core.Programming.Function,outputs: 2) — coerces tomsg.minimum_size/msg.maximum_size; missing folder or NaN short-circuits toCore.Flow.Stop. - List directory (
Core.FileSystem.List,optAbsolutePath: true,optSize: true,optIsDir: true) onmsg.selected_folder→msg.all_files_in_folder. - Loop (
Core.Flow.Label+Core.Programming.ForEachovermsg.all_files_in_folder→msg.current_file):- Size range check (
Core.Programming.Function,outputs: 2) — skips directories; keeps entries whereSize / 1024is within[minimum_size, maximum_size]. - In-range files: set
msg.file_to_delete = msg.current_file.Name, thenCore.FileSystem.Delete(continueOnError: true), thenCore.Flow.GoTothe loop label. - Out-of-range files:
Core.Flow.GoTothe loop label directly.
- Size range check (
- When the ForEach exhausts the list it falls through to
Core.Flow.Stop.
Behind the scenes
- Size comparisons convert bytes to KB (
Size / 1024) and are inclusive on both bounds — a 1024 B file withminimum_size = 1passes. - Directory entries are filtered out before the size check so nested folders aren't considered for deletion.
- Deletion is unconditional (no recycle bin, no confirmation) and uses
continueOnErrorso one locked file doesn't abort the loop.