-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizer.sh
57 lines (43 loc) · 1.47 KB
/
organizer.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Set the target directory to the current working directory
TARGET_DIR="${1:-$(pwd)}"
# Create subfolders for file types
create_folders() {
mkdir -p "$TARGET_DIR"/Images
mkdir -p "$TARGET_DIR"/Documents
mkdir -p "$TARGET_DIR"/Videos
mkdir -p "$TARGET_DIR"/Music
mkdir -p "$TARGET_DIR"/Archives
mkdir -p "$TARGET_DIR"/Others
}
# Move files to their respective folders
organize_files() {
echo "Organizing files in $TARGET_DIR..."
# Move image files
mv "$TARGET_DIR"/*.{jpg,jpeg,png,gif,bmp,tiff,svg,ico,avif} "$TARGET_DIR"/Images/ 2>/dev/null
# Move document files
mv "$TARGET_DIR"/*.{pdf,doc,docx,txt,ppt,pptx,xls,xlsx,epub} "$TARGET_DIR"/Documents/ 2>/dev/null
# Move video files
mv "$TARGET_DIR"/*.{mp4,mkv,avi,mov,wmv,flv} "$TARGET_DIR"/Videos/ 2>/dev/null
# Move music files
mv "$TARGET_DIR"/*.{mp3,wav,aac,flac,ogg} "$TARGET_DIR"/Music/ 2>/dev/null
# Move archive files
mv "$TARGET_DIR"/*.{zip,tar.gz,tar.bz2,rar,7z} "$TARGET_DIR"/Archives/ 2>/dev/null
# Move remaining files to 'Others'
mv "$TARGET_DIR"/* "$TARGET_DIR"/Others/ 2>/dev/null
}
# Main function to run the script
main() {
# Check if the target directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo "Error: Directory $TARGET_DIR does not exist."
exit 1
fi
# Create necessary folders
create_folders
# Organize files
organize_files
echo "File organization complete."
}
# Execute the script
main