-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup-by-date
More file actions
33 lines (26 loc) · 924 Bytes
/
group-by-date
File metadata and controls
33 lines (26 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Check if there are selected files
if [ "$#" -eq 0 ]; then
zenity --error --text="Няма избрани файлове!"
exit 1
fi
# Loop through each file
for file in "$@"; do
if [ -f "$file" ]; then
# Get file creation date
creation_date=$(stat --format='%w' "$file" | cut -d ' ' -f1)
# Get modification date if no creation date
if [ "$creation_date" == "-" ]; then
creation_date=$(stat --format='%y' "$file" | cut -d ' ' -f1)
fi
# Get year and month
year=$(date -d "$creation_date" +'%Y')
month=$(date -d "$creation_date" +'%m')
# Create directories
target_dir="./${year}/${month}"
mkdir -p "$target_dir"
# Move file to directory
mv "$file" "$target_dir"
fi
done
zenity --info --text="Избраните файлове са групирани по дата."