in reply to Read all the file path having text document

While endorsing the recommendations of others to use one of the fine File::Find group of modules, I would also point out that in your regex m/.txt/ the '.' (dot) is a regex metacharacter that matches any character except a newline (or any character at all if the /s regex switch is used). Try m{ \. txt }xms for greater specificity.

See perlre, particularly the Regular Expressions and /s switch sub-sections.

Replies are listed 'Best First'.
Re^2: Read all the file path having text document
by navzit (Initiate) on Nov 30, 2008 at 11:10 UTC
    Hi Monks, Thanks for the help . I completely changed my code and its working , though its taking 4 minutes to get the path of all the text documents. I have a 120 GB hardisk and only 40 GB contains text document. Can I make it faster?Navzit
    use File::Find::Rule; my $rule = File::Find::Rule->new; $rule->file; $rule->name( '*.txt' ); my @files = $rule->in("/" ); open(W,"> index.txt")|| die "can't open index.txt file"; foreach $files_name (@files) { print W $files_name ; print W "\n"; }
      Compare your code to the code produced by find2perl / -type f -iname '*\.txt'

      Depending on your computer and disk specs, 4 minutes may not be all that bad.