1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2025-04-11 05:36:04 -05:00

chg: Changed folderify to a shell script

This commit is contained in:
Sayantan Santra 2025-02-28 12:20:39 -06:00
parent 1d0e7ae338
commit 04ba04620a
Signed by: SinTan1729
GPG key ID: 0538DD402EA50898
2 changed files with 27 additions and 33 deletions

View file

@ -1,33 +0,0 @@
#!/usr/bin/env python3
# This is a simple script to find all video files in a folder and move them into their own folders.
# It also detects .srt subtitle files with matching names and moves them into their corresponding
# video file's folder.
import os
from pathlib import Path
path = os.getcwd()
files = (file for file in os.listdir(path)
if os.path.isfile(file) and Path(file).suffix in ['.mkv', '.mp4', '.avi', '.3gp'])
ctr = 0
for x in files:
filename = Path(x)
basename = str(filename.with_suffix(''))
if not os.path.isdir(basename):
os.mkdir(basename)
else:
print('The folder '+basename +
' already exists, please deal with that file manually.')
continue
os.rename(path+"/"+x, path+"/"+basename+"/"+x)
if os.path.isfile(basename+'.srt'):
os.rename(path+'/'+basename+'.srt', path +
'/'+basename+'/'+basename+'.srt')
if os.path.isfile(basename+'.en.srt'):
os.rename(path+'/'+basename+'.en.srt', path +
'/'+basename+'/'+basename+'.en.srt')
ctr += 1
print(str(ctr)+' folder(s) created.')

27
folderify.sh Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# This is a simple script to find all video files in a folder and move them into their own folders.
# It also detects .srt subtitle files with matching names and moves them into their corresponding
# video file's folder.
process_file () {
filename="$(basename "$file")"
echo "Processing $filename..."
without_ext="${filename%.*}"
if [ -d "$without_ext" ]; then
echo "The directory $without_ext alreaddy exists. Please process the file manually."
else
mkdir "$without_ext"
mv "$filename" "$without_ext/"
find . -type f -regextype posix-egrep -iregex "\./$without_ext(\.[a-z]{2})?\.srt" \
-exec mv "{}" "$without_ext/" \;
fi
}
counter=0
find . -type f -regextype posix-egrep -iregex '.*\.(mkv|mp4)$' -print0 | while IFS= read -r -d '' file; do
process_file
done