Created
August 27, 2023 08:52
-
-
Save hiAndrewQuinn/0891f3a2f1e39d9b1432005cc0d938c9 to your computer and use it in GitHub Desktop.
Create YYYY/MM/DD folders for the next 5 years.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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