Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hello Monks! I am a novice at Perl and need help with a code I have written. I am trying to grab all files with a certain extension using File::Find::Rule. The problem I have is that I am looking two specific directories using a 'while' loop with a counter for the files but for some reason the $directory path does not set to the 'Archive' option when $count = 0. After looking for files, I write them to a log for output. Please see my code below. Any help would be greatly appreciated. Thanks!

use strict; use warnings; use File::Find::Rule; my $directory = 'C:\Test\WMA_calls'; my $output_file = 'C:\Test\Results\output.txt'; my $count=0; my @files; while($count < 2) { print $count; $directory = 'C:\Test\Calls\Archive' if $count eq 0; $directory = 'C:\Test\Calls\History' if $count eq 1; @files = File::Find::Rule->file() ->name( "*.wma", "*.wmv" ) + ->in( $directory ); $count++; } if(@files) { open FILE, ">", $output_file or die "Can't open file, $output_file +: $!"; foreach(@files) { print FILE "$_\n"; } close FILE; } else { print "\n\nError!! No files found"; } exit 0;

Update: I was able to fix the above code and get it to work but the issue now is that I have more than 4000+ files in the two folders and its taking a really long time for the script to complete. Any advice on a more efficient/less memory hog way? Thanks again for the responses!

Update: Thank you for all the responses! I believe I was not clear on the original description of what I am trying to accomplish. I am trying to read all files of certain type from a given directory and all its subdirectories and eventually log all these filenames. From the previous responses I have been able to get a working code but when I did a dry run in Production, where I have over a million files I will be logging, its taking over 2hrs for just one directory read. Is there a more efficient/less memory consumption way I can do this? the dry run has taken over 100 MB of memory and counting...


In reply to Trouble with File::Find::Rule by sowais

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2015-07-04 02:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (57 votes), past polls