Skip to content

Instantly share code, notes, and snippets.

@AleixMT
Last active May 22, 2023 00:26
Show Gist options
  • Save AleixMT/2e1c3faba7556cad020fa3ce28876ae1 to your computer and use it in GitHub Desktop.
Save AleixMT/2e1c3faba7556cad020fa3ce28876ae1 to your computer and use it in GitHub Desktop.
Put all the files with the same name without extension in the current working directory into a new folder which has the same name.
shopt -s nullglob
rev()
{
copy=$1
len=${#copy}
for((i=$len-1;i>=0;i--)); do rev="$rev${copy:$i:1}"; done
echo $rev
}
for filename in *; do
if [ -d "${filename}" ]; then
continue
fi
if [ "${filename}" == "putinfolders.sh" ] || [ "${filename}" == "desktop.ini" ]; then
continue
fi
filename_noext="$(rev "$(rev "${filename}" | cut -d "." -f2-)")"
mkdir -p "${filename_noext}"
for this_movie_elem in "${filename_noext}".*; do
mv "${this_movie_elem}" "${filename_noext}"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment