View difference between Paste ID: 8bmvTTT8 and VBr4jbaX
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
## 
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, 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
14+
## Have script handle spaces better by usig a different delimiter
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 create a lowercased symlink to the uppercased vesion.  
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, and create a symlink to the new location at the old one.  
41
		if [[ "$strLowerCasedItem" != "$strItem" ]]; then
42-
		    ln -sT $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")
42+
		    mv -i $(echo "$strDir"'/'"$strItem") $(echo "$strDir"'/'"$strLowerCasedItem")  ## '-i' makes sure that we check with the user before clobbering
43
		    ln -sT $(echo "$strDir"'/'"$strLowerCasedItem") $(echo "$strDir"'/'"$strItem")
44
		fi
45
	    fi
46
	done
47
	echo '
48
Current directory after edit:  ' && ls -a --color=auto  ## Would be nice to hide . and ..
49
#    fi
50
}
51
52
## This loops the main loop through each subdirectory of the starting directory
53
for strDir in $(find -type d); do
54
    export strDir=$(echo "$strStartDir"$(echo "$strDir" | sed 's/^.//'))
55
    echo "$strDir"
56
    editingloop
57
done
58
59
exit 0