Created
July 18, 2025 13:52
-
-
Save sguzman/8f809cadf14956e76692f0e89e9ee481 to your computer and use it in GitHub Desktop.
Copy vids into dir and rename to S?E??
This file contains hidden or 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 | |
set dest_dir vids | |
mkdir -p $dest_dir | |
set log_file rename.log | |
echo "== Started at (date)==\n" >> $log_file | |
for f in (find . -type f -iname "*.mkv" | sort) | |
set filename (basename "$f") | |
# Extract SxxExx using direct substitution | |
set episode_code (string replace -r '.*(S[0-9]{2}E[0-9]{2}).*' '$1' -- "$filename") | |
# If extraction failed (didn't match), skip | |
if test -z "$episode_code" | |
echo "🚫 Skipping $filename (no SxxExx pattern found)" | tee -a $log_file | |
continue | |
end | |
set new_name "$episode_code.mkv" | |
set dest_path "$dest_dir/$new_name" | |
if test -e "$dest_path" | |
echo "⚠️ Skipping $filename → $new_name (already exists)" | tee -a $log_file | |
continue | |
end | |
echo "➡️ Copying $filename → $new_name" | tee -a $log_file | |
cp "$f" "$dest_path" | |
if test $status -eq 0 | |
echo "✅ Copied successfully" | tee -a $log_file | |
else | |
echo "❌ Failed to copy $filename" | tee -a $log_file | |
end | |
end | |
echo "\n== Finished at (date)==\n" >> $log_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment