1 |
On Monday 02 July 2007 22:47, Alex Schuster wrote: |
2 |
> Mich writes: |
3 |
> > I backed up my wife's WinXP fs using K3B and I used default settings |
4 |
> > which unfortunately converted all file names to CAPITALS and shortened |
5 |
> > them to 8 characters maximum, just like DOS would do. Is there a clever |
6 |
> > way to change some of them back to lower case (in batches within given |
7 |
> > directorates) so that she doesn't have to do it manually one by one? I |
8 |
> > do not want to change the access times, only the filename case letters. |
9 |
> |
10 |
> Create a script like this, name it lowercase.sh or something, and call it |
11 |
> with "lowercase file1 file2 dir1 dir2". I takes a list of files as |
12 |
> arguments (use * for all), and also works for directories. |
13 |
> So, "lowercase ." should convert all files and directories to lowercase. |
14 |
> |
15 |
> Put the script into your $PATH, or precede it by its path, e.g. |
16 |
> ./lowercase. To test it before possible messing up (I just wrote this |
17 |
> quickly) use the -t option: lowercase -t /path/to/your/files |
18 |
> |
19 |
> |
20 |
> #!/bin/bash |
21 |
> |
22 |
> # parse options (-t only) |
23 |
> while getopts "t" opt |
24 |
> do |
25 |
> case $opt in |
26 |
> t ) |
27 |
> test=true |
28 |
> ;; |
29 |
> * ) |
30 |
> exit 1 |
31 |
> esac |
32 |
> done |
33 |
> |
34 |
> shift $(( OPTIND-1 )) |
35 |
> |
36 |
> # loop over arguments |
37 |
> while (( $# )) |
38 |
> do |
39 |
> file=$1 |
40 |
> if [[ -d $file ]] |
41 |
> then |
42 |
> # call myself |
43 |
> $0 ${test:+-t} "$file"/* |
44 |
> elif [[ -f $file ]] |
45 |
> then |
46 |
> # conversion to lowercase |
47 |
> dir=$( dirname "$file" ) |
48 |
> base=$( basename "$file" ) |
49 |
> lower=$( echo "$base" | tr '[:upper:]' '[:lower:]' ) |
50 |
> newfile=${dir:+$dir/}$lower |
51 |
> [[ $file -ef $newfile ]] || |
52 |
> ${test:+echo} mv -v "$file" "$newfile" |
53 |
> else |
54 |
> echo "File not found: '$1'" |
55 |
> fi |
56 |
> shift |
57 |
> done |
58 |
> |
59 |
> |
60 |
> Alex |
61 |
|
62 |
Thanks Alex, I was trying your script, but just like Etaoin's script it does |
63 |
not go beyond level 1 in the directory. All the subdirectories and files |
64 |
within them stay in Capital Case. |
65 |
|
66 |
How can I change it to recursively look into the directory? |
67 |
-- |
68 |
Regards, |
69 |
Mick |