Skip to content

Instantly share code, notes, and snippets.

@hiAndrewQuinn
Created August 27, 2023 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiAndrewQuinn/0891f3a2f1e39d9b1432005cc0d938c9 to your computer and use it in GitHub Desktop.
Save hiAndrewQuinn/0891f3a2f1e39d9b1432005cc0d938c9 to your computer and use it in GitHub Desktop.
Create YYYY/MM/DD folders for the next 5 years.
#!/usr/bin/env fish
# Define the source and destination directories
set source_dir ~/Documents
set dest_root ~/Documents
# Loop through each file in the source directory
for file in $source_dir/*
if test -f $file
# Get the creation date of the file
set creation_date (stat -c %y $file | cut -d' ' -f1)
# Extract year, month, and day from the creation date
set -l year (string split -m1 $creation_date)
set -l month (string replace -r '[0-9]{4}-' '' $creation_date)
set -l day (string replace -r '[0-9]{4}-[0-9]{2}-' '' $creation_date)
# Create the destination directory path
set dest_dir $dest_root/$year/$month/$day
# Create the destination directory if it doesn't exist
mkdir -p $dest_dir
echo "Moving $file to $dest_dir"
# Move the file to the destination directory
mv $file $dest_dir/
echo "Moved $file to $dest_dir"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment