View difference between Paste ID: VBr4jbaX and FeRuYGa8
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
## 
3-
## "Lowercase all the things"
3+
## "CK2:  Work, damn you!"
4
## 
5
## Copyright (C) 2015 under CC0 (Creative Commons 0;  ie I waive all my copyright rights for this code)
6
## By 'Maiya78' from the Paradox forums
7
## 
8-
## From the current directory, recursively convert to lower case all file and directory names
8+
## From the current directory, recursively convert to lower case all file and directory names, creating symlinks to their original names
9
## Should ask for verification before overwriting an existing file.  
10
## !BROKEN! Should also decapitalize Cyrillic, Greek, and other mixed-case scripts.  
11
## 
12
## -----------------------------------------------------------------------------------------------------------
13
14
## Have script handle spaces
15
export IFS='
16
'
17
18
## Setting an important early variable
19
export strStartDir=$(pwd)
20
21
## Write in a function the loop that we'll use for to edit the files
22
function editingloop {
23
    cd "$strDir"
24
    ## Check to make sure current directory isn't empty
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
	echo '
27
_______________________________________________________________________
28
Entering current directory:  '"$strDir"
29
	echo '
30
Current directory before edit:  ' && ls -a --color=auto  ## Would be nice to hide . and ..
31
	## Dimensioning variables like a responsible person
32
	local strItem
33
	local strLowerCasedItem
34
	## Start the editing loop
35
	for strItem in $(ls); do
36
	    ## Save the computer some breath on . and ..
37
	    if [[ "$strItem" != '.' || '..' ]]; then
38
		## Set a variable equal to the lowercased vesion of the original filename
39
		export strLowerCasedItem=$(echo "$strItem" | tr '[A-Z]' '[a-z]')
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.  
40+
		## If this variable is the same as the original, then the original was already lowercased, so we skip it;  otherwise, we create a lowercased symlink to the uppercased vesion.  
41
		if [[ "$strLowerCasedItem" != "$strItem" ]]; then
42-
		    mv -i $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")  ## '-i' makes sure that we check with the user before clobbering
42+
		    ln -sT $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")
43
		fi
44
	    fi
45
	done
46
	echo '
47
Current directory after edit:  ' && ls -a --color=auto  ## Would be nice to hide . and ..
48
#    fi
49
}
50
51
## This loops the main loop through each subdirectory of the starting directory
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