Sunday, January 2, 2011

Sub Folders Files only display in perl

print "Enter the file path\n";
chomp($fpath=<STDIN>);
getfilenamesonly($fpath);

sub getfilenamesonly{
    $name = shift;
    $name =~s #\\#\/#gi;
    $name .= "/" unless $name =~ /\/$/i;
   
    foreach $file (glob($name.'*'))    {
        if(-d $file) {
            getfilenamesonly($file);
        }
        else {
            print $file, "\n";
        }
    }
}   

__END__
use strict;
use warnings;
use File::Find;
open(F1, ">1.txt");
find(\&subroute, "E:\\Purand\\EPS2GIF\\");
sub subroute{
print F1 "$File::Find::name\n";
}
close F1;

No comments: