script to find the files with very long names

P

pui ming Wong

My objective is to go down the current directory
and have the system tells me which files have their names
longer than say 26 characters

i think mixing the unix find command
with some other commands might do it.
But a perl script might do it more tidily and faster ?
 
M

Mirco Wahab

Thus spoke pui ming Wong (on 2006-06-12 09:34):
My objective is to go down the current directory
and have the system tells me which files have their names
longer than say 26 characters

You could use modules for that:

...
use File::Find;

my $directory = '.';

find
sub {
print "$_ =>", length, " ($File::Find::name)\n" if -f;
},
$directory;
...


In the sub-block provided to find,
the actual path is given in $_,
so its just a matter of asking
'length' for that.

Regards

Mirco
 
N

Nick of course

pui said:
My objective is to go down the current directory
and have the system tells me which files have their names
longer than say 26 characters

i think mixing the unix find command
with some other commands might do it.
But a perl script might do it more tidily and faster ?

perl -le 'length > 26 and print for <*>'
 
D

Dr.Ruud

pui ming Wong schreef:
My objective is to go down the current directory
and have the system tells me which files have their names
longer than say 26 characters

i think mixing the unix find command
with some other commands might do it.
But a perl script might do it more tidily and faster ?

For the current directory only:

perl -wle 'while(<*>){print if length()>26}'

Files only:

perl -wle 'while(<*>){-f and length()>26 and print}'

Current directory and below:

find -E . -type f -regex ".*/[^/]{26,}"
 
T

Tad McClellan

pui ming Wong said:
My objective is to go down the current directory
and have the system tells me which files have their names
longer than say 26 characters


perl -MFile::Find -le 'find sub{print $File::Find::name if length > 26}, "."'
 
J

Jürgen Exner

File::Find with a simple
{print if lenght > 26}
as the wanted function should do nicely.

jue
 
D

David Combs

find . -name "??????????????????????????*"

That's 26 question marks, or if you prefer to specify a value:

find . -name "$(printf "%26s*"|tr ' ' '?')"

Regards,

Ed.

If 26 is what you *really* want to do, isn't there nowadays
a \{26\} suffix that will do it? (At least that's what
works in emacs.)

David
 
J

Jürgen Exner

Ouch!

Ok, here's a fish:

use strict; use warnings;
use File::Find;
sub wanted{print "$_\n" if length>26;}
find(\&wanted, '.');

jue
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Jürgen Exner
use strict; use warnings;
use File::Find;
sub wanted{print "$_\n" if length>26;}
find(\&wanted, '.');

Wrong. You do not want to use $_ there (or use 'nochdir'). Better, use

pfind . "length > 26"

Hope this helps,
Ilya
 
J

Jürgen Exner

Ilya Zakharevich said:
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Jürgen Exner
use strict; use warnings;
use File::Find;
sub wanted{print "$_\n" if length>26;}
find(\&wanted, '.');

Wrong. You do not want to use $_ there (or use 'nochdir').

Why? The docs say
"$_" [contains] the current filename
As far as I can tell that's exactly what the OP asked for: filenames
longer than 26 characters.
Better, use
pfind . "length > 26"

C:\tmp>perldoc -f pfind
No documentation for perl function `pfind' found

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top