Hey
I am trying to write a script that allows me to recursivley search through a directory to find the longest file name. I am trying to do this using perl.
Problem i have it that it is taking the directory and counting it as filename length
Code:
#!/usr/bin/perl -w
#program to print longest file name in a directory - resursive
if (! @ARGV) {
print "Must have a directroy argument\n";
exit;
}
open(FIND, "find . -print |") || die "Couldn't run find: $!\n";
$length = 0;
FILE:
while ($file = <FIND>) {
chop $file;
if (! -d $file) {
print "$file\n";
$newlength = `echo $file | wc -c`;
if ($newlength > $length) {
$length = $newlength;
$name = $file;
}
next FILE;
}
}
print "Longest File was $name\n";
Anyone got any ideas - even it i could just split the a line
like ./test/res/file1 so i could have access to the last part after the final /
but it would have to be generic for if it was only ./test/file2
Anyone with any idea please help
Thanks