Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
not sure if this has been raised before...would other monks like to see the code written in questions and answers syntax highlighted for easier reading? e.g. gvim style. i pinched code from another post to show how it would look if colored by me with Vim.
#! perl -w

use strict;
use File::Copy;

my $infile = "C:/radtrans/doclisth.chr";

my ( $yr, $mo, $dy ) = (localtime)<font color="#00ffff">5</font>,<font color="#00ffff">4</font>,<font color="#00ffff">3</font>;
my $outfile = sprintf( "C:/radtrans/%04d%02d%02d.txt",$yr+1900,$mo+1,$
+dy );

my $staticdir = "C:\\radtrans\\";

open IN, "<$infile" or die "Couldn't open $infile, $!";
open OUT,">$outfile" or die "Couldn't open $outfile, $!";

while (<IN>) {
    chomp;
    my @fields   = split /|/;

    my $newfile = $fields<font color="#00ffff">0</font>;
    my $path_str = $fields<font color="#00ffff">12</font>;

    do { warn "Empty field 13"; next } unless $path_str;
    my @path = split /\\/, $path_str;
    my $dir = join "\\", @path <font color="#00ffff">0</font>, <font color="#00ffff">1</font>, <font color="#00ffff">2</font>, <font color="#00ffff">3</font>, <font color="#00ffff">4</font>, <font color="#00ffff">5</font>, <font color="#00ffff">6</font> ;

    $newfile =~ s/$/.rtf/;

    my $out = join ('|', @fields<font color="#00ffff">0.</font>.<font color="#00ffff">9</font>) . "@" . $staticdir . $newfile;

    print OUT "$out\n";

    process_dir($dir,$newfile);

}
close IN;

sub process_dir {

    my ($dir, $newfile) = @_;

    do { warn "$dir does not exist!\n"; return } unless -e $dir;
    opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return
};
    while ( my $file = readdir DIR ) {

        print "dir: $dir file:$file newfile:$newfile\n";
        #before the next unless statements.

        next unless -f "$dir\\$file";

        next unless $file =~ m/\.rtf$/i;

        copy( "$dir\\$file", "C:\\temp\\$newfile" )
          or die "Failed to copy $file: $!\n";
    }
}

Edit by tye, add READMORE tag


In reply to syntax highlighting of code in perlmonks forums by aquarium

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-30 03:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found