public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Change the case of file names
@ 2007-07-02 20:59 Mick
  2007-07-02 21:08 ` Hemmann, Volker Armin
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Mick @ 2007-07-02 20:59 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

Hi All,

I backed up my wife's WinXP fs using K3B and I used default settings which 
unfortunately converted all file names to CAPITALS and shortened them to 8 
characters maximum, just like DOS would do.  Is there a clever way to change 
some of them back to lower case (in batches within given directorates) so 
that she doesn't have to do it manually one by one?  I do not want to change 
the access times, only the filename case letters. 
-- 
Regards,
Mick

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 20:59 [gentoo-user] Change the case of file names Mick
@ 2007-07-02 21:08 ` Hemmann, Volker Armin
  2007-07-02 21:25   ` Mick
  2007-07-02 21:38   ` Albert Hopkins
  2007-07-02 21:19 ` Etaoin Shrdlu
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: Hemmann, Volker Armin @ 2007-07-02 21:08 UTC (permalink / raw
  To: gentoo-user

On Montag, 2. Juli 2007, Mick wrote:
> Hi All,
>
> I backed up my wife's WinXP fs using K3B and I used default settings which
> unfortunately converted all file names to CAPITALS and shortened them to 8
> characters maximum, just like DOS would do.  Is there a clever way to
> change some of them back to lower case (in batches within given
> directorates) so that she doesn't have to do it manually one by one?  I do
> not want to change the access times, only the filename case letters.

that wasn't k3b - that is an limitation of iso9660. A limitation MS forced 
down our throats.

To prevent that in the future, make sure that you tick the 'joliet' option 
under filesystems (in older k3b) or choose 'linux/unix and windows (with 
newer k3b).

About the renaming -  maybe this might help:
*  sys-apps/rename
      Latest version available: 1.3
      Latest version installed: [ Not Installed ]
      Size of downloaded files: [no/bad digest]
      Homepage:    http://rename.berlios.de/
      Description: tool for easily renaming files
      License:     GPL-2
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 20:59 [gentoo-user] Change the case of file names Mick
  2007-07-02 21:08 ` Hemmann, Volker Armin
@ 2007-07-02 21:19 ` Etaoin Shrdlu
  2007-07-02 21:47 ` Alex Schuster
  2007-07-02 22:08 ` Willie Wong
  3 siblings, 0 replies; 16+ messages in thread
From: Etaoin Shrdlu @ 2007-07-02 21:19 UTC (permalink / raw
  To: gentoo-user

On Monday 2 July 2007 22:59, Mick wrote:
> Hi All,
>
> I backed up my wife's WinXP fs using K3B and I used default settings
> which unfortunately converted all file names to CAPITALS and shortened
> them to 8 characters maximum, just like DOS would do.  Is there a
> clever way to change some of them back to lower case (in batches
> within given directorates) so that she doesn't have to do it manually
> one by one?  I do not want to change the access times, only the
> filename case letters.

Assuming there are no spaces in the names, something like:

cd $targetdir

for n in *; do

  newname=`echo $n | tr -s 'A-Z' 'a-z'`
  mv $n $newname

done

should work. It might be possile to do the same using bash alone, but I'm 
too lazy to check now.
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 21:08 ` Hemmann, Volker Armin
@ 2007-07-02 21:25   ` Mick
  2007-07-03  2:42     ` Hemmann, Volker Armin
  2007-07-02 21:38   ` Albert Hopkins
  1 sibling, 1 reply; 16+ messages in thread
From: Mick @ 2007-07-02 21:25 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

On Monday 02 July 2007 22:08, Hemmann, Volker Armin wrote:

> that wasn't k3b - that is an limitation of iso9660. A limitation MS forced
> down our throats.

Aaargh!  :-@

> To prevent that in the future, make sure that you tick the 'joliet' option
> under filesystems (in older k3b) or choose 'linux/unix and windows (with
> newer k3b).

Thanks, I found that out after I paid attention to the default settings.  I am 
still not sure why the k3b default is not the linux/unix format.

> About the renaming -  maybe this might help:
> *  sys-apps/rename
>       Latest version available: 1.3
>       Latest version installed: [ Not Installed ]
>       Size of downloaded files: [no/bad digest]
>       Homepage:    http://rename.berlios.de/
>       Description: tool for easily renaming files
>       License:     GPL-2

Thanks!  Seems a useful little app.  Will try it out.
-- 
Regards,
Mick

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 21:08 ` Hemmann, Volker Armin
  2007-07-02 21:25   ` Mick
@ 2007-07-02 21:38   ` Albert Hopkins
  2007-07-03  2:44     ` Hemmann, Volker Armin
  1 sibling, 1 reply; 16+ messages in thread
From: Albert Hopkins @ 2007-07-02 21:38 UTC (permalink / raw
  To: gentoo-user

On Mon, 2007-07-02 at 23:08 +0200, Hemmann, Volker Armin wrote:
> that wasn't k3b - that is an limitation of iso9660. A limitation MS
> forced 
> down our throats. 

I wouldn't be quick to blame Microsoft for iso9660.  It was designed to
be a one-size-fits-all standard so it would work on all (well, most)
systems.  There is even a part in the standard for file versions as to
work with VMS systems (I guess you could blame Digital for that one).
OTOH there are plenty of non-standard, incompatible extensions to
ISO9660 you can blame (Rock Ridge: Unix, Joliet: Microsoft, El Torito:
IBM, Mac OS: Apple).
 
--
Albert W. Hopkins

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 20:59 [gentoo-user] Change the case of file names Mick
  2007-07-02 21:08 ` Hemmann, Volker Armin
  2007-07-02 21:19 ` Etaoin Shrdlu
@ 2007-07-02 21:47 ` Alex Schuster
  2007-07-08 21:18   ` Mick
  2007-07-02 22:08 ` Willie Wong
  3 siblings, 1 reply; 16+ messages in thread
From: Alex Schuster @ 2007-07-02 21:47 UTC (permalink / raw
  To: gentoo-user

Mich writes:

> I backed up my wife's WinXP fs using K3B and I used default settings
> which unfortunately converted all file names to CAPITALS and shortened
> them to 8 characters maximum, just like DOS would do.  Is there a clever
> way to change some of them back to lower case (in batches within given
> directorates) so that she doesn't have to do it manually one by one?  I
> do not want to change the access times, only the filename case letters.

Create a script like this, name it lowercase.sh or something, and call it 
with "lowercase file1 file2 dir1 dir2". I takes a list of files as 
arguments (use * for all), and also works for directories. 
So, "lowercase ." should convert all files and directories to lowercase.

Put the script into your $PATH, or precede it by its path, e.g. ./lowercase. 
To test it before possible messing up (I just wrote this quickly) use 
the -t option: lowercase -t /path/to/your/files


#!/bin/bash

# parse options (-t only)
while getopts "t" opt
do
	case $opt in
	t )
		test=true
		;;
	* )
		exit 1
	esac
done

shift $(( OPTIND-1 ))

# loop over arguments
while (( $# ))
do
	file=$1
	if [[ -d $file ]]
	then
		# call myself
		$0 ${test:+-t} "$file"/*
	elif [[ -f $file ]]
	then
		# conversion to lowercase
		  dir=$( dirname  "$file" )
		 base=$( basename "$file" )
		lower=$( echo "$base" | tr '[:upper:]' '[:lower:]' )
		newfile=${dir:+$dir/}$lower
		[[ $file -ef $newfile ]] ||
			${test:+echo} mv -v "$file" "$newfile"
	else
		echo "File not found: '$1'"
	fi
	shift
done


	Alex
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 20:59 [gentoo-user] Change the case of file names Mick
                   ` (2 preceding siblings ...)
  2007-07-02 21:47 ` Alex Schuster
@ 2007-07-02 22:08 ` Willie Wong
  2007-07-03  5:51   ` Mick
  3 siblings, 1 reply; 16+ messages in thread
From: Willie Wong @ 2007-07-02 22:08 UTC (permalink / raw
  To: gentoo-user

On Mon, Jul 02, 2007 at 09:59:17PM +0100, Penguin Lover Mick squawked:
> Hi All,
> 
> I backed up my wife's WinXP fs using K3B and I used default settings which 
> unfortunately converted all file names to CAPITALS and shortened them to 8 
> characters maximum, just like DOS would do.  Is there a clever way to change 
> some of them back to lower case (in batches within given directorates) so 
> that she doesn't have to do it manually one by one?  I do not want to change 
> the access times, only the filename case letters. 

from 'info sed' -> Examples

     #! /bin/sh
     # rename files to lower/upper case...
     #
     # usage:
     #    move-to-lower *
     #    move-to-upper *
     # or
     #    move-to-lower -R .
     #    move-to-upper -R .
     #
     
     help()
     {
        cat << eof
     Usage: $0 [-n] [-r] [-h] files...
     
     -n      do nothing, only see what would be done
     -R      recursive (use find)
     -h      this message
     files   files to remap to lower case
     
     Examples:
            $0 -n *        (see if everything is ok, then...)
            $0 *
     
            $0 -R .
     
     eof
     }
     
     apply_cmd='sh'
     finder='echo "$@" | tr " " "\n"'
     files_only=
     
     while :
     do
         case "$1" in
             -n) apply_cmd='cat' ;;
             -R) finder='find "$@" -type f';;
             -h) help ; exit 1 ;;
             *) break ;;
         esac
         shift
     done
     
     if [ -z "$1" ]; then
             echo Usage: $0 [-h] [-n] [-r] files...
             exit 1
     fi
     
     LOWER='abcdefghijklmnopqrstuvwxyz'
     UPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     
     case `basename $0` in
             *upper*) TO=$UPPER; FROM=$LOWER ;;
             *)       FROM=$UPPER; TO=$LOWER ;;
     esac
     
     eval $finder | sed -n '
     
     # remove all trailing slashes
     s/\/*$//
     
     # add ./ if there is no path, only a filename
     /\//! s/^/.\//
    
     # save path+filename
     h
     
     # remove path
     s/.*\///
     
     # do conversion only on filename
     y/'$FROM'/'$TO'/
     
     # now line contains original path+file, while
     # hold space contains the new filename
     x
     
     # add converted file name to line, which now contains
     # path/file-name\nconverted-file-name
     G
     
     # check if converted file name is equal to original file name,
     # if it is, do not print nothing
     /^.*\/\(.*\)\n\1/b
     
     # now, transform path/fromfile\n, into
     # mv path/fromfile path/tofile and print it
     s/^\(.*\/\)\(.*\)\n\(.*\)$/mv "\1\2" "\1\3"/p
     
     ' | $apply_cmd



..... which is probably a bit of an overkill. 
(And don't ask me why I remember this particular example being in the
sed info page ;p )

HTH, 

W


-- 
"`The best way to get a drink out of a Vogon is to stick 
your finger down his throat...'" 

- The Book, on one of the Vogon's social inadequacies. 
Sortir en Pantoufles: up 206 days, 20:29
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 21:25   ` Mick
@ 2007-07-03  2:42     ` Hemmann, Volker Armin
  0 siblings, 0 replies; 16+ messages in thread
From: Hemmann, Volker Armin @ 2007-07-03  2:42 UTC (permalink / raw
  To: gentoo-user

On Montag, 2. Juli 2007, Mick wrote:
> On Monday 02 July 2007 22:08, Hemmann, Volker Armin wrote:
> > that wasn't k3b - that is an limitation of iso9660. A limitation MS
> > forced down our throats.
>
> Aaargh!  :-@
>
> > To prevent that in the future, make sure that you tick the 'joliet'
> > option under filesystems (in older k3b) or choose 'linux/unix and windows
> > (with newer k3b).
>
> Thanks, I found that out after I paid attention to the default settings.  I
> am still not sure why the k3b default is not the linux/unix format.
>

because all systems can read iso9660. But not all systems can read rockridge 
or joliet. iso9660 is the most compatible option, so it is the default.
 
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 21:38   ` Albert Hopkins
@ 2007-07-03  2:44     ` Hemmann, Volker Armin
  0 siblings, 0 replies; 16+ messages in thread
From: Hemmann, Volker Armin @ 2007-07-03  2:44 UTC (permalink / raw
  To: gentoo-user

On Montag, 2. Juli 2007, Albert Hopkins wrote:
> On Mon, 2007-07-02 at 23:08 +0200, Hemmann, Volker Armin wrote:
> > that wasn't k3b - that is an limitation of iso9660. A limitation MS
> > forced
> > down our throats.
>
> I wouldn't be quick to blame Microsoft for iso9660.  It was designed to
> be a one-size-fits-all standard so it would work on all (well, most)
> systems.

I don't blame MS for iso9660 - I blame MS for the name limitations ;)

> There is even a part in the standard for file versions as to 
> work with VMS systems (I guess you could blame Digital for that one).
> OTOH there are plenty of non-standard, incompatible extensions to
> ISO9660 you can blame (Rock Ridge: Unix, Joliet: Microsoft, El Torito:
> IBM, Mac OS: Apple).

ElTorito something completly different....

http://en.wikipedia.org/wiki/El_Torito_(CD-ROM_standard)

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 22:08 ` Willie Wong
@ 2007-07-03  5:51   ` Mick
  2007-07-04  7:03     ` Kent Fredric
  0 siblings, 1 reply; 16+ messages in thread
From: Mick @ 2007-07-03  5:51 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 379 bytes --]

On Monday 02 July 2007 23:08, Willie Wong wrote:

> from 'info sed' -> Examples
>
>      #! /bin/sh
>      # rename files to lower/upper case...
[snip...]

> (And don't ask me why I remember this particular example being in the
> sed info page ;p )

WOW! I didn't expect so many ways to get this done, thanks guys for all your 
suggestions.  :)
-- 
Regards,
Mick

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-03  5:51   ` Mick
@ 2007-07-04  7:03     ` Kent Fredric
  2007-07-04 18:44       ` Mick
  0 siblings, 1 reply; 16+ messages in thread
From: Kent Fredric @ 2007-07-04  7:03 UTC (permalink / raw
  To: gentoo-user

On 7/3/07, Mick <michaelkintzios@gmail.com> wrote:
> On Monday 02 July 2007 23:08, Willie Wong wrote:
>
> > from 'info sed' -> Examples
> >
> >      #! /bin/sh
> >      # rename files to lower/upper case...
> [snip...]
>
> > (And don't ask me why I remember this particular example being in the
> > sed info page ;p )
>
> WOW! I didn't expect so many ways to get this done, thanks guys for all your
> suggestions.  :)
> --
> Regards,
> Mick
>
>

If you want something that should work on all linuxes in theory
without the need for changing the disk standard to something thats
potentially incompatible with a given system ( say for example for
some reason your target machine cant for some forsaken reason read
joliet enabled disks ) you may wish to look for the 'trans.tbl'
option, which to the best of my knowlege creates a file on the disk
explaining the real-full-length version of a shortened filename
without having to munge the disk standard. ( I think of it like a
meta-data-in-file-on-filesystem instead of
alter-filesystem-spec-to-handle-metadata option )

( Ok, its obsolete, but has saved my bacon once or twice )

http://en.wikipedia.org/wiki/TRANS.TBL
http://en.wikipedia.org/wiki/ISO_9660#Extensions

-- 
Kent
ruby -e '[1, 2, 4, 7, 0, 9, 5, 8, 3, 10, 11, 6, 12, 13].each{|x|
print "enNOSPicAMreil kdrtf@gma.com"[(2*x)..(2*x+1)]}'
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-04  7:03     ` Kent Fredric
@ 2007-07-04 18:44       ` Mick
  2007-07-04 20:18         ` Kent Fredric
  0 siblings, 1 reply; 16+ messages in thread
From: Mick @ 2007-07-04 18:44 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

On Wednesday 04 July 2007 08:03, Kent Fredric wrote:

> If you want something that should work on all linuxes in theory
> without the need for changing the disk standard to something thats
> potentially incompatible with a given system ( say for example for
> some reason your target machine cant for some forsaken reason read
> joliet enabled disks ) you may wish to look for the 'trans.tbl'
> option, which to the best of my knowlege creates a file on the disk
> explaining the real-full-length version of a shortened filename
> without having to munge the disk standard. ( I think of it like a
> meta-data-in-file-on-filesystem instead of
> alter-filesystem-spec-to-handle-metadata option )
>
> ( Ok, its obsolete, but has saved my bacon once or twice )
>
> http://en.wikipedia.org/wiki/TRANS.TBL
> http://en.wikipedia.org/wiki/ISO_9660#Extensions

Thanks Kent, how do I specify that option?  Is it in k3b?
-- 
Regards,
Mick

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-04 18:44       ` Mick
@ 2007-07-04 20:18         ` Kent Fredric
  0 siblings, 0 replies; 16+ messages in thread
From: Kent Fredric @ 2007-07-04 20:18 UTC (permalink / raw
  To: gentoo-user

On 7/5/07, Mick <michaelkintzios@gmail.com> wrote:
> On Wednesday 04 July 2007 08:03, Kent Fredric wrote:
>
> > If you want something that should work on all linuxes in theory
> > without the need for changing the disk standard to something thats
> > potentially incompatible with a given system ( say for example for
> > some reason your target machine cant for some forsaken reason read
> > joliet enabled disks ) you may wish to look for the 'trans.tbl'
> > option, which to the best of my knowlege creates a file on the disk
> > explaining the real-full-length version of a shortened filename
> > without having to munge the disk standard. ( I think of it like a
> > meta-data-in-file-on-filesystem instead of
> > alter-filesystem-spec-to-handle-metadata option )
> >
> > ( Ok, its obsolete, but has saved my bacon once or twice )
> >
> > http://en.wikipedia.org/wiki/TRANS.TBL
> > http://en.wikipedia.org/wiki/ISO_9660#Extensions
>
> Thanks Kent, how do I specify that option?  Is it in k3b?
> --
> Regards,
> Mick
>
>

I believe its on the 'advanced settings' or something page with old k3b.
The new one its listed as  'create TRANS.TBL' files' under the
customize button on the filesystems tab of the properties dialog.

-- 
Kent
ruby -e '[1, 2, 4, 7, 0, 9, 5, 8, 3, 10, 11, 6, 12, 13].each{|x|
print "enNOSPicAMreil kdrtf@gma.com"[(2*x)..(2*x+1)]}'
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-02 21:47 ` Alex Schuster
@ 2007-07-08 21:18   ` Mick
  2007-07-08 23:00     ` Alex Schuster
  2007-07-09  8:00     ` Etaoin Shrdlu
  0 siblings, 2 replies; 16+ messages in thread
From: Mick @ 2007-07-08 21:18 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]

On Monday 02 July 2007 22:47, Alex Schuster wrote:
> Mich writes:
> > I backed up my wife's WinXP fs using K3B and I used default settings
> > which unfortunately converted all file names to CAPITALS and shortened
> > them to 8 characters maximum, just like DOS would do.  Is there a clever
> > way to change some of them back to lower case (in batches within given
> > directorates) so that she doesn't have to do it manually one by one?  I
> > do not want to change the access times, only the filename case letters.
>
> Create a script like this, name it lowercase.sh or something, and call it
> with "lowercase file1 file2 dir1 dir2". I takes a list of files as
> arguments (use * for all), and also works for directories.
> So, "lowercase ." should convert all files and directories to lowercase.
>
> Put the script into your $PATH, or precede it by its path, e.g.
> ./lowercase. To test it before possible messing up (I just wrote this
> quickly) use the -t option: lowercase -t /path/to/your/files
>
>
> #!/bin/bash
>
> # parse options (-t only)
> while getopts "t" opt
> do
> 	case $opt in
> 	t )
> 		test=true
> 		;;
> 	* )
> 		exit 1
> 	esac
> done
>
> shift $(( OPTIND-1 ))
>
> # loop over arguments
> while (( $# ))
> do
> 	file=$1
> 	if [[ -d $file ]]
> 	then
> 		# call myself
> 		$0 ${test:+-t} "$file"/*
> 	elif [[ -f $file ]]
> 	then
> 		# conversion to lowercase
> 		  dir=$( dirname  "$file" )
> 		 base=$( basename "$file" )
> 		lower=$( echo "$base" | tr '[:upper:]' '[:lower:]' )
> 		newfile=${dir:+$dir/}$lower
> 		[[ $file -ef $newfile ]] ||
> 			${test:+echo} mv -v "$file" "$newfile"
> 	else
> 		echo "File not found: '$1'"
> 	fi
> 	shift
> done
>
>
> 	Alex

Thanks Alex, I was trying your script, but just like Etaoin's script it does 
not go beyond level 1 in the directory.  All the subdirectories and files 
within them stay in Capital Case.

How can I change it to recursively look into the directory?
-- 
Regards,
Mick

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-08 21:18   ` Mick
@ 2007-07-08 23:00     ` Alex Schuster
  2007-07-09  8:00     ` Etaoin Shrdlu
  1 sibling, 0 replies; 16+ messages in thread
From: Alex Schuster @ 2007-07-08 23:00 UTC (permalink / raw
  To: gentoo-user

Mick writes:

> Thanks Alex, I was trying your script, but just like Etaoin's script it
> does not go beyond level 1 in the directory.  All the subdirectories and
> files within them stay in Capital Case.
>
> How can I change it to recursively look into the directory?

That's strange. I tried that and had no problem.

Here's a slightly enhanced version with more options. -h shows a help, -d 
also converts directories, -r turns recursive operation on, and -u would 
convert into uppercase instead. So you would use it like that:
  lowercase -dr *
This assumes you also want the directory names converted. Leave the -d 
option off if not. And add a -t first so you see what would be done, in 
case the script would mess things up. It seems to work, but was written 
rather quickly. If all seems okay, start it again without the -t.

If it still don't work, you can also use the find command to process each 
file individually:
  find . -exec lowercase -d \{\} \;
Or this if you like to change files only:
  find . -type f -exec lowercase \{\} \;
	
Feel free to email me directly if you are still having trouble, so we won't 
bother the list.

	Alex

#!/bin/bash

# parse options
unset oDir oRec oTest oUpper
while getopts "dhrtu" opt
do
	case $opt in
	h )
		echo "
${0##*/} [-dhrtu] files...
Convert files into lowercase

Options:
  -d  convert directories, too
  -h  show this help
  -r  recursive
  -t  test, show what would be done
  -u  change to uppercase instead
"
		exit 0
		;;
	d )	  oDir=true ;;
	r )	  oRec=true ;;
	t )	 oTest=true ;;
	u )	oUpper=true ;;
	* )	exit 1
	esac
done
shift $(( OPTIND-1 ))

# decide whether to convert to lowercase or uppercase
if [[ $oUpper ]]
then
	from=[:lower:]
	  to=[:upper:]
else
	from=[:upper:]
	  to=[:lower:]
fi

# make * expand to empty string when no files are found
shopt -s nullglob

# loop over arguments
while (( $# ))
do
	aFile=$1
	shift
	
	# check if file exists
	if ! [[ -e $aFile ]]
	then
		echo "File not found: '$aFile'"
		continue
	fi
	
	# process directories recursively first
	if [[ -d $aFile ]] && [[ $oRec ]] && [[ $aFile/* ]]
	then
		$0 ${oDir:+-d} ${oTest:+-t} ${oUpper:+-u} -r "$aFile"/*
	fi
	
	# skip directories without -d option
	[[ -d $aFile ]] && ! [[ $oDir ]] && continue
	
	# create new name
	 dir=$( dirname  "$aFile" )
	base=$( basename "$aFile" )
	newFile=${dir:+$dir/}$( echo "$base" | tr "$from" "$to" )
	
	# rename file if necessary
	[[ $aFile -ef $newFile ]] ||
		${oTest:+echo} mv -v "$aFile" "$newFile"
done


wonko@weird test --> ../lowercase -rd *
»A/A/X« -> »A/A/x«
»A/A/Y« -> »A/A/y«
»A/A« -> »A/a«
»A« -> »./a«
»B/B« -> »B/b«
»B« -> »./b«
»C/X« -> »C/x«
»C« -> »./c«
»X« -> »./x«
»Y« -> »./y«
--
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [gentoo-user] Change the case of file names
  2007-07-08 21:18   ` Mick
  2007-07-08 23:00     ` Alex Schuster
@ 2007-07-09  8:00     ` Etaoin Shrdlu
  1 sibling, 0 replies; 16+ messages in thread
From: Etaoin Shrdlu @ 2007-07-09  8:00 UTC (permalink / raw
  To: gentoo-user

On Sunday 8 July 2007 23:18, Mick wrote:

> Thanks Alex, I was trying your script, but just like Etaoin's script
> it does not go beyond level 1 in the directory.  All the
> subdirectories and files within them stay in Capital Case.
>
> How can I change it to recursively look into the directory?

One way is to use recursion (btw, my previous script had an error: tr 
must be invoked without the -s option):

#!/bin/bash

# $1 is the file/dir name
function change_case() {
  newname=`echo $1 | tr 'A-Z' 'a-z'`
  echo "$1 -> $newname"  # for debug
  mv $1 $newname
}

function scan() {
  local i
  for i in $*; do
    if [ -d $i ]; then
      # $i is a directory, recurse and change case
      cd $i
      scan *
      cd ..
      change_case $i
    else
      # regular file
      change_case $i
    fi
  done
}

# start
if [ $# -eq 0 ]; then
  echo "Must specify root directory"
  exit 1
fi

shopt -s nullglob    # to account for empty dirs
cd $1
scan *
exit 0
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-07-09  7:57 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-02 20:59 [gentoo-user] Change the case of file names Mick
2007-07-02 21:08 ` Hemmann, Volker Armin
2007-07-02 21:25   ` Mick
2007-07-03  2:42     ` Hemmann, Volker Armin
2007-07-02 21:38   ` Albert Hopkins
2007-07-03  2:44     ` Hemmann, Volker Armin
2007-07-02 21:19 ` Etaoin Shrdlu
2007-07-02 21:47 ` Alex Schuster
2007-07-08 21:18   ` Mick
2007-07-08 23:00     ` Alex Schuster
2007-07-09  8:00     ` Etaoin Shrdlu
2007-07-02 22:08 ` Willie Wong
2007-07-03  5:51   ` Mick
2007-07-04  7:03     ` Kent Fredric
2007-07-04 18:44       ` Mick
2007-07-04 20:18         ` Kent Fredric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox