Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Script moulded by freddy87
- read -p "Enter the filetype you want to rename: ." extension #option to select filename extension
- file_num=$(ls -1 *.$extension| grep -v '/$' | wc -l) #counts files in folder of type $extension
- echo "Number of files to rename: "$file_num #output for peace of mind
- padding=${#file_num} #gets length of file_num for padding to give each filename
- echo "Length of padding in filename: "$padding #output for peace of mind
- a=1
- for i in *.$extension; do
- new=$(printf "%0"$padding"d."$extension "$a") #$padding appropriate to number of files
- if [ "$new" = "$i" ]; then
- echo "Error: Filenames matching already"
- elif [ "$new" != "$i" ]; then
- mv -- "$i" "$new" #renames files
- let a=a+1
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement