[Gllug] Finding filenames with special characters (was Mass renaming of files)

Ian Norton bredroll at atari.org
Sun May 11 09:34:06 UTC 2003


hence perl being best quited to this, 

before this nice list introduced me to mmv i always just did a ls -1 >
/tmp/ls.txt and used sed to replace \n with 'newname'\n and \^ with mv

always worked for me, was a bit of a lazy hack,

bred

On Sun, May 11, 2003 at 09:37:34AM +0100, Richard Jones wrote:
> On Sun, May 11, 2003 at 07:48:49AM +0100, Simon Morris wrote:
> > * " | ?
> 
> Essentially the problem here is with quoting. I think you'll find
> it's hard to write a simple script which copes with these cases.
> However, here is a not-so-simple script which will work:
> 
> ----------------------------------------------------------------------
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $root = $ARGV[0];
> warn "root = $root\n";
> 
> sub visit
>   {
>     my $fn = shift;
>     my $dir = shift;
> 
>     warn "visiting $dir\n";
>     opendir DIR, $dir or die "visit: $dir: $!";
>     my @files = readdir DIR;
>     closedir DIR;
> 
>     foreach (@files) {
>       next if /^\.{1,2}$/;
>       $_ = &$fn ($dir, $_);
>       visit ($fn, "$dir/$_") if -d "$dir/$_";
>     }
>   }
> 
> visit (sub {
> 	 my $dir = shift;
> 	 local $_ = shift;
> 	 my $old = "$dir/$_";
> 	 tr/:/_/;
> 	 rename $old, "$dir/$_" or warn "rename: $old, $dir/$_: $!";
> 	 $_
>        }, $root);
> ----------------------------------------------------------------------
> 
> Run it as ./rename.pl TOPDIR
> 
> > There are also some directorys and files with no names! How am I
> > supposed to find them???
> 
> With no names ... this sounds unlikely. Valid Unix filenames have to
> be at least one character long. Do a 'ls -lb' of the offending
> directory and post it here.
> 
> > It would probably be better to stop the OS allowing daft filenames like
> > these. Is that possible?
> 
> Are these mounted by the clients using Samba or appleshare? If so then
> there might be a way to configure or patch these tools so that they
> refuse to create files with unusual names.
> 
> Rich.
> 
> -- 
> Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
> http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
> MONOLITH is an advanced framework for writing web applications in C, easier
> than using Perl & Java, much faster and smaller, reusable widget-based arch,
> database-backed, discussion, chat, calendaring:
> http://www.annexia.org/freeware/monolith/
> 
> 
> -- 
> Gllug mailing list  -  Gllug at linux.co.uk
> http://list.ftech.net/mailman/listinfo/gllug

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS dpu s--: a-- C++++ UL++ P+++ L+++ E--- W-- N+ o K w---
O M-- V-- PS++ PE-- Y+ PGP+ t+++ 5++ X++ R+++ !tv b DI D----
G++ e+ h++ r++ y+++
------END GEEK CODE BLOCK------
----- Message of the Hour ------
Moooo :-)


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list