You could open the directory with opendir and read it with readdir. Iterate over the names returned by readdir. Use the -f operator to make sure you've got a file. Using the -s operator, you could determine the file size. Set $/ to \1048576. Open the too-big file. Start up a while loop, reading through the file. For each "record", open an output file and print out that record, then close that output file, and move onto the next file in the directory. Use a counter to generate unique splitfile names.

Update:
A few hours later I had a moment to put it to code:

use strict; use warnings; my $path = "c:/path/to/files"; my $maxsize = 1048576; opendir my $dirhandle, $path or die $!; foreach my $file ( readdir $dirhandle ) { next unless -f $file; next unless -s $file > $maxsize; my $count = 0; open my $in, '<', "$path/$file" or die $!; { local $/ = \$maxsize; while ( my $record = <$in> ) { my $outname = "$file.split" . sprintf "%03s", $count++; open my $out, '>', "$path/$outname" or die $!; print $out $record; close $out or die $!; } } close $in; }

Dave


In reply to Re: Text File Size by davido
in thread Text File Size by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.