zsh-users
 help / color / mirror / code / Atom feed
* Re: capitalizing file names
@ 2007-04-26  5:57 Artur Penttinen
  2007-04-26  7:16 ` Phil Pennock
  0 siblings, 1 reply; 7+ messages in thread
From: Artur Penttinen @ 2007-04-26  5:57 UTC (permalink / raw)
  To: zsh-users

26.04.07, 09:16, Alexy Khrabrov <deliverable@gmail.com>:

> I need to rename a series of files on Mac OS X, to reflect case
> difference.  I have multi-word file names such as
> alexy_070411_1971.dng
> -- which must become
> Alexy_070411_1971.DNG
> -- that is, I need to capitalize the filename and the extension.  Lest
> of writing a perl/ruby script, is there a zsh way?

  autoload zmv
  zmv '(*).(*)' '${(C)1}.${2:u}'
  
-- 
wbw, artur


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

* Re: capitalizing file names
  2007-04-26  5:57 capitalizing file names Artur Penttinen
@ 2007-04-26  7:16 ` Phil Pennock
  2007-04-30  4:49   ` Bart Schaefer
  2007-05-14 17:50   ` Peter Stephenson
  0 siblings, 2 replies; 7+ messages in thread
From: Phil Pennock @ 2007-04-26  7:16 UTC (permalink / raw)
  To: zsh-users

On 2007-04-26 at 09:57 +0400, Artur Penttinen wrote:
> > I need to rename a series of files on Mac OS X, to reflect case
> 
> > difference.  I have multi-word file names such as
> 
> > alexy_070411_1971.dng

>   autoload zmv
> 
>   zmv '(*).(*)' '${(C)1}.${2:u}'

Nope, on MacOS with its case-preserving-but-insensitive file-system that
yields:

% zmv '(*).(*)' '${(C)1}.${2:u}'
zmv: error(s) in substitution:
file exists: Alexy_070411_1971.DNG
(Probably the same file, owing to file system limitations.)

In the definition of zmv: [[ $f != $g && $f -ef $g ]]
$f is the original filename, $g is the generated filename and they're
the same file (-ef, equal file).

-Phil


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

* Re: capitalizing file names
  2007-04-26  7:16 ` Phil Pennock
@ 2007-04-30  4:49   ` Bart Schaefer
  2007-05-14 17:50   ` Peter Stephenson
  1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2007-04-30  4:49 UTC (permalink / raw)
  To: zsh-users

On Apr 26, 12:16am, Phil Pennock wrote:
}
} >   zmv '(*).(*)' '${(C)1}.${2:u}'
} 
} Nope, on MacOS with its case-preserving-but-insensitive file-system that
} yields:
} 
} % zmv '(*).(*)' '${(C)1}.${2:u}'
} zmv: error(s) in substitution:
} file exists: Alexy_070411_1971.DNG
} (Probably the same file, owing to file system limitations.)

Since you've already established that MacOS doesn't mishandle a "mv" where
the source and destination file names refer to the same file, it should
work just to do:

zmv -f '(*).(*)' '${(C)1}.${2:u}'

In general, though, I'd think this must be done in two steps.  E.g.:

% zmv '(*).(*)' 'tmp_${(C)1}.${2:u}'
% zmv 'tmp_(*)' '$1'


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

* Re: capitalizing file names
  2007-04-26  7:16 ` Phil Pennock
  2007-04-30  4:49   ` Bart Schaefer
@ 2007-05-14 17:50   ` Peter Stephenson
  2007-05-14 17:56     ` Peter Stephenson
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-05-14 17:50 UTC (permalink / raw)
  To: zsh-users

Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> % zmv '(*).(*)' '${(C)1}.${2:u}'
> zmv: error(s) in substitution:
> file exists: Alexy_070411_1971.DNG
> (Probably the same file, owing to file system limitations.)
> 
> In the definition of zmv: [[ $f != $g && $f -ef $g ]]
> $f is the original filename, $g is the generated filename and they're
> the same file (-ef, equal file).

Presumably if the files really are equivalent, it's safe to attempt
to mv in the hope that the file system knows what it's doing.  We've
already tested for $f = $g at this point.

Unfortunately, Cygwin mv (6.4) still barfs on this, presumably because it
hasn't been told about case-insensitive case-preserving file systems.
However, this ought at least to be no worse than what zmv was outputting.
It would be possible to use an intermediate, but doing it safely in general
is a pain (and no longer atomic, which wasn't guaranteed before but would
have been the case anyway on a lot of systems).  It turns out you can get
it to work with "zmodload zsh/files", because zsh's mv doesn't do that
test, but that has other effects.  Now with local feature support...

Index: Functions/Misc/zmv
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/zmv,v
retrieving revision 1.11
diff -u -r1.11 zmv
--- Functions/Misc/zmv	16 Jan 2004 15:29:27 -0000	1.11
+++ Functions/Misc/zmv	14 May 2007 17:42:22 -0000
@@ -262,13 +262,8 @@
     continue
   elif [[ -n $from[$g] && ! -d $g ]]; then
     errs=($errs "$f and $from[$g] both map to $g")
-  elif [[ -f $g && -z $opt_f ]]; then
-    if [[ $f != $g && $f -ef $g ]]; then
-      errs=($errs "file exists: $g
-(Probably the same file, owing to file system limitations.)")
-    else
-      errs=($errs "file exists: $g")
-    fi
+  elif [[ -f $g && -z $opt_f && ! ($f -ef $g) ]]; then
+    errs=($errs "file exists: $g")
   fi
   from[$g]=$f
   to[$f]=$g


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


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

* Re: capitalizing file names
  2007-05-14 17:50   ` Peter Stephenson
@ 2007-05-14 17:56     ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2007-05-14 17:56 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <pws@csr.com> wrote:
> Presumably if the files really are equivalent, it's safe to attempt
> to mv in the hope that the file system knows what it's doing.  We've
> already tested for $f = $g at this point.

...although this only applies if the action really is renaming.

Index: Functions/Misc/zmv
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/zmv,v
retrieving revision 1.11
diff -u -r1.11 zmv
--- Functions/Misc/zmv	16 Jan 2004 15:29:27 -0000	1.11
+++ Functions/Misc/zmv	14 May 2007 17:55:17 -0000
@@ -262,13 +262,8 @@
     continue
   elif [[ -n $from[$g] && ! -d $g ]]; then
     errs=($errs "$f and $from[$g] both map to $g")
-  elif [[ -f $g && -z $opt_f ]]; then
-    if [[ $f != $g && $f -ef $g ]]; then
-      errs=($errs "file exists: $g
-(Probably the same file, owing to file system limitations.)")
-    else
-      errs=($errs "file exists: $g")
-    fi
+  elif [[ -f $g && -z $opt_f && ! ($f -ef $g && $action = mv) ]]; then
+    errs=($errs "file exists: $g")
   fi
   from[$g]=$f
   to[$f]=$g


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


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

* Re: capitalizing file names
  2007-04-26  5:16 Alexy Khrabrov
@ 2007-04-26  5:52 ` Phil Pennock
  0 siblings, 0 replies; 7+ messages in thread
From: Phil Pennock @ 2007-04-26  5:52 UTC (permalink / raw)
  To: zsh-users

On 2007-04-25 at 22:16 -0700, Alexy Khrabrov wrote:
>  I need to rename a series of files on Mac OS X, to reflect case
>  difference.  I have multi-word file names such as
> 
>  alexy_070411_1971.dng
> 
>  -- which must become
> 
>  Alexy_070411_1971.DNG
> 
>  -- that is, I need to capitalize the filename and the extension.  Lest
>  of writing a perl/ruby script, is there a zsh way?

If you can assume that all filenames have an extension:

for f in ...whatever...
do
	mv $f ${(C)f:r}.${(U)f:e}
done

See zshexpn(1); (C) to capitalise words, (U) to upper-case them, :r and
:e for extracting components of the filename (root & extension).

Successfully tested on MacOS X.

-Phil


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

* capitalizing file names
@ 2007-04-26  5:16 Alexy Khrabrov
  2007-04-26  5:52 ` Phil Pennock
  0 siblings, 1 reply; 7+ messages in thread
From: Alexy Khrabrov @ 2007-04-26  5:16 UTC (permalink / raw)
  To: zsh-users

I need to rename a series of files on Mac OS X, to reflect case
difference.  I have multi-word file names such as

alexy_070411_1971.dng

-- which must become

Alexy_070411_1971.DNG

-- that is, I need to capitalize the filename and the extension.  Lest
of writing a perl/ruby script, is there a zsh way?

Cheers,
Alexy


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

end of thread, other threads:[~2007-05-14 17:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-26  5:57 capitalizing file names Artur Penttinen
2007-04-26  7:16 ` Phil Pennock
2007-04-30  4:49   ` Bart Schaefer
2007-05-14 17:50   ` Peter Stephenson
2007-05-14 17:56     ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
2007-04-26  5:16 Alexy Khrabrov
2007-04-26  5:52 ` Phil Pennock

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).