View difference between Paste ID: FeRuYGa8 and EPh8g5pB
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
## 
3-
## "LowerIt"
3+
## "Lowercase all the things"
4
## 
5-
## Original code found here:  http://www.linuxjournal.com/content/convert-filenames-lowercase ;  though this looks nothing like it.  
5+
## Copyright (C) 2015 under CC0 (Creative Commons 0;  ie I waive all my copyright rights for this code)
6-
## Modified by Maiya78 to change directory names, to work recursively, and to support unicode filenames on GNU systems.  I also copyedited the comments.  :3 
6+
## By 'Maiya78' from the Paradox forums
7
## 
8
## From the current directory, recursively convert to lower case all file and directory names
9
## Should ask for verification before overwriting an existing file.  
10
## !BROKEN! Should also decapitalize Cyrillic, Greek, and other mixed-case scripts.  
11-
## ------------------------------------------------------------------------------------------------------------
11+
12
## -----------------------------------------------------------------------------------------------------------
13-
## Make sure we're in the right directory
13+
14-
export strStartDir="$(pwd)"
14+
## Have script handle spaces
15
export IFS='
16
'
17
18-
    if [[ -d "$strDir" ]]; then
18+
## Setting an important early variable
19-
        cd "$strDir"
19+
export strStartDir=$(pwd)
20-
        ## Check to make sure current directory isn't empty
20+
21-
#        if [[ $(echo $strDir/*) != $(echo $strDir'/*') ]]; then  ## Doesn't seem to be working.  :\ 
21+
22-
            echo '
22+
23
    cd "$strDir"
24
    ## Check to make sure current directory isn't empty
25-
            echo '
25+
#    if [[ $(ls -a) != {. ..} ]]; then  ## Not sure how to do this without a loop, and don't want to use a loop for it.  
26-
Current directory before edit:  ' && ls
26+
	echo '
27-
            ## Start the editing loop
27+
28-
            for strItem in "$(ls -a)"; do
28+
29-
                ## Save the computer some breath on . and ..
29+
	echo '
30-
                if [[ "$strItem" != '.' || '..' ]]; then
30+
Current directory before edit:  ' && ls -a --color=auto  ## Would be nice to hide . and ..
31-
                    ## Set a variable equal to the lowercased vesion of the original filename
31+
	## Dimensioning variables like a responsible person
32-
                    strLowerCasedItem=$(echo "$strItem" | sed 's/[[:upper:]]*/\L&/')
32+
	local strItem
33-
                    ## If this variable is the same as the original, then the original was already lowercased, so we skip it.  
33+
	local strLowerCasedItem
34-
                    if [[ "$strLowerCasedItem" != "$strItem" ]]; then
34+
	## Start the editing loop
35-
                        mv -i $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")  ## '-i' makes sure that we check with the user before clobbering
35+
	for strItem in $(ls); do
36-
                    fi
36+
	    ## Save the computer some breath on . and ..
37-
                fi
37+
	    if [[ "$strItem" != '.' || '..' ]]; then
38-
            done
38+
		## Set a variable equal to the lowercased vesion of the original filename
39-
            echo '
39+
		export strLowerCasedItem=$(echo "$strItem" | tr '[A-Z]' '[a-z]')
40-
Current directory after edit:  ' && ls
40+
		## If this variable is the same as the original, then the original was already lowercased, so we skip it;  otherwise, we rename it to the lowercased vesion.  
41-
#        fi
41+
		if [[ "$strLowerCasedItem" != "$strItem" ]]; then
42-
    fi
42+
		    mv -i $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")  ## '-i' makes sure that we check with the user before clobbering
43
		fi
44
	    fi
45-
## Lowercase all items in the starting directory
45+
	done
46-
export strDir="$strStartDir"
46+
	echo '
47-
editingloop
47+
Current directory after edit:  ' && ls -a --color=auto  ## Would be nice to hide . and ..
48-
unset strDir
48+
#    fi
49
}
50
51-
for strDir in $(echo "$strStartDir"/*); do
51+
52-
editingloop
52+
for strDir in $(find -type d); do
53
    export strDir=$(echo "$strStartDir"$(echo "$strDir" | sed 's/^.//'))
54
    echo "$strDir"
55
    editingloop
56
done
57
58
exit 0