Last active
June 11, 2017 00:23
-
-
Save jcanfield/2974916c96ffb7357385f3e9e9b6674f to your computer and use it in GitHub Desktop.
Rename files in a folder to match folder name (useful for htpc usage)
This file contains 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
#!/bin/bash | |
# SYPOPSIS: Rename files in folder to match folder. | |
# CREDIT: Unamed user on superuser or superadmin. If you find this, let me know and I will add you to the credits. | |
# UPCOMING: Allow for secondary input such as `rename-files-to-folder $MOVIENAME` so not to rename all movies in directory just one or two. | |
find * -type f -maxdepth 1 | while read file | |
do | |
dirname="$(dirname "$file")" | |
new_name="${dirname##*/}" | |
file_ext=${file##*.} | |
if [ -n "$file_ext" -a -n "$dirname" -a -n "$new_name" ] | |
then | |
echo "mv '$file' '$dirname/$new_name.$file_ext'" | |
fi | |
done |
Not working on FreeNAS/FreeBSD 10.3-STABLE. Working on solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script was tested on Ubuntu 16.10 and Debian 8.8. I have not had the chance to test on other system but do have friends and colleagues who will test on various platforms. All that is in use is basic
bash
scripting,find
andmv
.