Nodes/AAA Metadata System/Flatten Nested Files v0.2
ComfyUI Node

Flatten Nested Files v0.2

A ComfyUI node in Eric/Images with 15 inputs and 5 outputs.

By EricRollei·Created 9 months ago·Updated 8 months ago· 12
Flatten Nested Files v0.2
    • status_message
    • files_moved
    • paired_files_moved
    • stats_json
    • log_output
    main_directory
    operation_modeflatten_only
    file_typesimages_only
    flatten_depth0
    respect_paired_filestrue
    skip_organized_folderstrue
    organize_by_typefalse
    sidecar_handlingkeep_with_images
    remove_empty_folderstrue
    dry_runfalse
    handle_conflictsrename
    max_scan_depth100
    custom_type_mappings
    custom_folder_mappings
    preserve_source_foldernone
    CategoryEric/Images

    Inputs (15)

    NameTypeDefaultDescription
    main_directorySTRINGMain directory where all files will be moved to
    operation_modeCOMBOflatten_onlyChoose operation mode: • flatten_only: Move all files directly into main_directory (NO type subfolders) • flatten_and_organize: Move files AND create type subfolders (images/, movies/, etc.) • organize_only: Don't move files up, just organize them in their current locations Note: organize_by_type parameter can override flatten_only to add type folders
    file_typesoptCOMBOimages_onlyWhich files to process: • images_only: .jpg, .png, .webp, .gif, etc. • all_media: Images + videos (.mp4, .mov, etc.) • all_files: Everything including .txt, .pdf, etc.
    flatten_depthoptINT00–10Flatten nested folders to this depth: • 0 = Move ALL files to main directory • 1 = Keep 1st level subfolders, flatten everything inside them • 2 = Keep 2 levels, flatten below that Example: If main=instagram and depth=1, processes each profile folder (alisha.maghi/, 777luckyfish/) independently
    respect_paired_filesoptBOOLEANtrueKeep paired files together (e.g., photo.jpg + photo.xmp + photo.txt). Paired files share the same base filename and are moved as a group.
    skip_organized_foldersoptBOOLEANtrueSkip folders that already have type organization (contain images/, movies/, text/ subfolders). Useful to avoid re-organizing already processed directories.
    organize_by_typeoptBOOLEANfalseCreate type-based subfolders: • images/ for .jpg, .png, etc. • movies/ for .mp4, .mov, etc. • text/ for .txt, .pdf, .md • sidecars/ for .xmp, .json (unless kept with images) • other/ for unrecognized types When True: Always creates type folders (even with flatten_only mode) When False with flatten_only: All files go directly into main_directory
    sidecar_handlingoptCOMBOkeep_with_imagesWhere to put sidecar/metadata files: • keep_with_images: Put .xmp/.json/.txt in images/ folder • separate_folder: Put all sidecars in sidecars/ folder • keep_txt_only: Only .txt with images, others to sidecars/
    remove_empty_foldersoptBOOLEANtrueDelete empty subdirectories after moving files. Leaves a clean directory structure with no leftover empty folders.
    dry_runoptBOOLEANfalsePreview mode - show what WOULD be moved without actually moving anything. Great for testing settings before committing changes.
    handle_conflictsoptCOMBOrenameHow to handle duplicate filenames: • rename: Add (1), (2), etc. to filename • skip: Leave original, don't move duplicate • overwrite: Replace existing file with new one
    max_scan_depthoptINT1001–200Maximum folder nesting depth to scan. Increase if you have very deeply nested folders (46+ levels). Prevents infinite loops and excessive scanning.
    custom_type_mappingsoptSTRINGJSON mapping file extensions to custom folder names. Example: { ".pdf": "documents", ".cr2": "raw_photos", ".psd": "photoshop" } Files with these extensions go to specified folders instead of default type folders.
    custom_folder_mappingsoptSTRINGJSON mapping file TYPES to custom folder names. Example: { "movies": "videos", "images": "photos", "text": "documents" } Renames the default type folders (images→photos, movies→videos, etc.).
    preserve_source_folderoptCOMBOnoneAdd original folder name to filename to preserve context: • none: photo.jpg (no change) • prefix: alisha.maghi_photo.jpg • suffix: photo_alisha.maghi.jpg Useful when flattening to avoid name conflicts and maintain source info.

    Outputs (5)

    NameTypeDescription
    status_messageSTRING
    files_movedINT
    paired_files_movedINT
    stats_jsonSTRING
    log_outputSTRING