Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##
- ## "LowerIt"
- ##
- ## Original code found here: http://www.linuxjournal.com/content/convert-filenames-lowercase ; though this looks nothing like it.
- ## Modified by Maiya78 to change directory names, to work recursively, and to support unicode filenames on GNU systems. I also copyedited the comments. :3
- ##
- ## From the current directory, recursively convert to lower case all file and directory names
- ## Should ask for verification before overwriting an existing file.
- ##
- ## ------------------------------------------------------------------------------------------------------------
- ## Make sure we're in the right directory
- export strStartDir="$(pwd)"
- ## Write in a function the loop that we'll use for to edit the files
- function editingloop {
- if [[ -d "$strDir" ]]; then
- cd "$strDir"
- ## Check to make sure current directory isn't empty
- # if [[ $(echo $strDir/*) != $(echo $strDir'/*') ]]; then ## Doesn't seem to be working. :\
- echo '
- _______________________________________________________________________
- Entering current directory: '"$strDir"
- echo '
- Current directory before edit: ' && ls
- ## Start the editing loop
- for strItem in "$(ls -a)"; do
- ## Save the computer some breath on . and ..
- if [[ "$strItem" != '.' || '..' ]]; then
- ## Set a variable equal to the lowercased vesion of the original filename
- strLowerCasedItem=$(echo "$strItem" | sed 's/[[:upper:]]*/\L&/')
- ## If this variable is the same as the original, then the original was already lowercased, so we skip it.
- if [[ "$strLowerCasedItem" != "$strItem" ]]; then
- mv -i $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem") ## '-i' makes sure that we check with the user before clobbering
- fi
- fi
- done
- echo '
- Current directory after edit: ' && ls
- # fi
- fi
- }
- ## Lowercase all items in the starting directory
- export strDir="$strStartDir"
- editingloop
- unset strDir
- ## This loops the main loop through each subdirectory of the starting directory
- for strDir in $(echo "$strStartDir"/*); do
- editingloop
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement