[Linux-disciples] Troubles with 'rename'
Adam Rosi-Kessel
adam at rosi-kessel.org
Tue Jun 21 15:57:45 EDT 2005
Um, it seems like what you want to do was answered in the script I
posted that day:
http://lists.bostoncoop.net/pipermail/linux-disciples/2005-April/001222.html
One problem with your script is it gets sticky with depth vs. breadth
... the directory list in the for loop is generated first, and a parent
directory in your path may already be renamed by the time you get to it.
Stephen R Laniel wrote:
> On Sat, Apr 30, 2005 at 09:55:00AM -0400, Adam Rosi-Kessel wrote:
>
>>I don't think rename can handle that kind of target:
>>
>># mkdir some\ dir
>># touch some\ dir/some\ file
>># ls some\ dir
>>some file
>># rename "s/ /_/g" some\ dir/some\ file
>>Can't rename some dir/some file some_dir/some_file: No such file or directory
>
>
> I just ran into this again. My first guess is that 'rename'
> won't allow you to rename a file if your renaming rule would
> affect the file's parent directories as well. So
>
> rename 's/ /_/g' some_dir/some\ file
>
> would work fine, but
>
> rename 's/ /_/g' some\ dir/some_file
>
> does not.
>
> It seems like the solution to this is to use the find
> command, cd into the directory containing the file, rename
> the file, then back out and rename the parent directory.
> Something like this should do the trick, though some problem
> or another with embedded spaces is making this particular
> command fail:
>
> for i in $(find -depth -iname '*\ *'); do cd $(dirname $i); rename 's/ /_/g' "$i"; done
>
> Like I said, that's not quite working, but I suspect
> something like that would work.
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Linux-disciples mailing list
> Linux-disciples at lists.bostoncoop.net
> http://lists.bostoncoop.net/mailman/listinfo/linux-disciples
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20050621/c5b69cd3/signature.pgp
More information about the Linux-disciples
mailing list