Create target directories based on file creation metadata

Hello everyone,

i use rclone a lot and in various scenarios and so far everything works as expected.

I regularly use rclone moveto . myNextcloud:Photos/Albumname --include “*.JPG” -P from my cameras sdcard directory to move my files directly to my nextcloud instance.

What i am trying to figure out is, if rclone (or my shell?) can use the file creation date from the images as the target directory so my .jpg’s are automatically stored and sorted in folders?

I tried various search engines,read the rclone docs about the move/moveto commands and read the rclone page about filtering but i was not able to construct the desired solution for me.

Would love to know if anyone has some shell/rclone experience that could help me out here!

thanks and have a nice day

Paul

It has to be a few lines (hopefully) of shell script.

How exactly it should work? Assuming you have bunch of jpg files. How their destination folders’ names should be derived from metadata?

YYYY ?

YYYYMM ?

YYYYMMDD ?

I would like the path on the remote to look like this: myNextcloud:Photos/YYYY/MM/DD/example.JPG

the file creation date on the sdcard reflects the day of shooting the picture which would be enough for me to have a basic organisation on my remote. I think this should work for me as long as the date is set correctly on the camera but that has not been an issue so far.

OK. Here you are how I would approach it in bash.

I think what is needed are two steps.

  1. Get all unique YYYY/MM/DD values

rclone lsf can give you all files’ date/time values:

$ rclone lsf --files-only --format t --quiet .
2025-09-12 16:32:35
2025-09-12 20:19:34
2025-09-22 10:48:06
...

Below bash command can extract all unique YYYY-MM-DD files’ values from current directory:

$ rclone lsf --files-only --format t --quiet . | cut -c1-10 | sort | uniq
2025-09-12
2025-09-22
...
  1. Move files to their final destinations

Now you can loop over such list and assuming that $date is single row value you can move files matching specific date (using metadata filters) to specific directory (here it will be YYYY-MM-DD)

$ rclone move --metadata-include "mtime=${date}*" . dest_remote:${date}

You can transform (simple string manipulation) destination dest_remote:${date} into something else if needed, like dest_remote:YY/MM/DD if you need hierarchical structure e.g.:

$ rclone move --metadata-include "mtime=${date}*" . dest_remote:${date/-/\/}

okay, it took me a few tries until i got the date format right, it seems like i need to escape the / first.

but it seems to do exactly what i want! thank you very much

#!/bin/bash

# Step 1: Get all unique YYYY-MM-DD values from files in the current directory
unique_dates=$(rclone lsf --files-only --format t --quiet . | cut -c1-10 | sort | uniq)

# Step 2: Loop over each unique date and move files to their destination
for date in $unique_dates; do
    echo -e "\e[93mMoving .JPG files modified on $date to myNextcloud:Photos/${date//-/\/}"
    echo -e "\e[39m"
    rclone move --include "*.JPG" --metadata-include "mtime=${date}*" . "myNextcloud:Photos/${date//-/\/}" -P
done

echo -e "\e[92mAll .JPG files have been organized by date."

Output:

[paul@computer 101_FUJI]$ ~/Maintenance/move-sdcard-jpg-to-nextcloud.sh 
Moving files modified on 2025-10-11 to dest_remote:Photos/2025/10/11
Transferred:        7.362 GiB / 7.362 GiB, 100%, 17.517 MiB/s, ETA 0s
Checks:               355 / 355, 100%, Listed 651
Deleted:              355 (files), 0 (dirs), 7.362 GiB (freed)
Renamed:              355
Transferred:          355 / 355, 100%
Elapsed time:      5m41.1s
Moving files modified on 2025-10-12 to dest_remote:Photos/2025/10/12
Transferred:      209.654 MiB / 209.654 MiB, 100%, 17.471 MiB/s, ETA 0s
Checks:                11 / 11, 100%, Listed 296
Deleted:               11 (files), 0 (dirs), 209.654 MiB (freed)
Renamed:               11
Transferred:           11 / 11, 100%
Elapsed time:        12.6s
Moving files modified on 2025-10-13 to dest_remote:Photos/2025/10/13
Transferred:        3.627 GiB / 3.627 GiB, 100%, 17.717 MiB/s, ETA 0s
Checks:               175 / 175, 100%, Listed 285
Deleted:              175 (files), 0 (dirs), 3.627 GiB (freed)
Renamed:              175
Transferred:          175 / 175, 100%
Elapsed time:      3m58.3s
Moving files modified on 2025-10-15 to dest_remote:Photos/2025/10/15
Transferred:        1.867 GiB / 1.867 GiB, 100%, 13.888 MiB/s, ETA 0s
Checks:               110 / 110, 100%, Listed 110
Deleted:              110 (files), 0 (dirs), 1.867 GiB (freed)
Renamed:              110
Transferred:          110 / 110, 100%
Elapsed time:      2m35.8s
All files have been organized by date.

I kept the –-dry-run option on purpose to test if everything works before actually touching the files :slight_smile:

EDIT: added color to terminal output in bash script

1 Like

Well done. It definitely does its job. Thx for sharing.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.