Add Scripts/sort-files.sh
This commit is contained in:
parent
6d3e1875f9
commit
f3a0723994
|
@ -0,0 +1,40 @@
|
|||
#!/bin/usr/env bash
|
||||
|
||||
## Run this script in any directory that's filled with random files
|
||||
## you want to sort by file extensions into respective subdiorectories.
|
||||
|
||||
# Change to current directory
|
||||
cd $(pwd)
|
||||
|
||||
# Create subdirectories
|
||||
dest="_sortiert"
|
||||
mkdir -p "${dest}"
|
||||
|
||||
dirs=("Images" "Archives" "Videos" "Audio" "Documents" "Misc")
|
||||
for dir in "${dirs[@]}"; do
|
||||
mkdir -p "${dest}/${dir}"
|
||||
done
|
||||
|
||||
# Function for moving files
|
||||
move() {
|
||||
local dir="$1"
|
||||
shift
|
||||
local extensions=("$@")
|
||||
|
||||
for ext in "${extensions[@]}"; do
|
||||
mv ./*."${ext}" "${dest}/${dir}" 2>/dev/null
|
||||
done
|
||||
}
|
||||
|
||||
# Move files by extension
|
||||
move "Images" "jpg" "jpeg" "JPG" "png" "PNG" "svg" "gif" "webp" "bmp"
|
||||
move "Archives" "zip" "rar" "tar" "gz"
|
||||
move "Videos" "MOV" "mov" "mp4" "mkv" "avi"
|
||||
move "Audio" "mp3" "ogg" "mpeg" "wav" "flac"
|
||||
move "Documents" "doc*" "odt" "pdf" "txt" "ods"
|
||||
|
||||
# Move misc
|
||||
find . -maxdepth 1 -type f -exec mv {} "${dest}/Misc" \;
|
||||
|
||||
# Remove empty directories
|
||||
find "${dest}" -type d -empty -delete
|
Loading…
Reference in New Issue