Can someone please help me search a rtf file?

I'm able to find desired text in a txt file but not a rtf file.

I would like to find the date after the text "Date of Last Update:" and count the number of signatures in the file.

I've not had luck with RTF::Tokenizer or Win32::OLE.

I will eventually print the directory, filename, date the file was uploaded, date of last update, and number of signatures.

Thanks for your help.

use strict; use warnings; use File::stat; use Time::localtime; use RTF::Tokenizer; require Win32::OLE; sub get_data_from_file ; my $fullpath = my $dir = 'C:\Test'; my %hash; opendir (DIR, $dir) or die $!; while (my $dir = readdir(DIR)) { my $file = $fullpath = 'C:\Test\\' . $dir; opendir (FILE, $file) or die $!; while (my $file = readdir(FILE)) { if ($file =~/RTF/ || $file =~/rtf/ ){ # if ( $file =~/txt/ ){ # print "fullpath = $fullpath file is $file\n"; # $hash{$dir}{$file}{PATH} = $fullpath . '\\' . $file; my $upload_date = ctime(stat($fullpath . '\\' . $file) +->mtime); $hash{$dir}{$file}{UPLOAD_DATE} = $upload_date; # print "dir is $dir file is $file date is $hash{$dir} +{$file}{UPLOAD_DATE}\n"; # print $hash{$dir}{$file}{PATH}; open (IN, $fullpath . '\\' . $file) or die ("Can't ope +n the input file $!"); while ( <IN> ){ # Try to find date on this line "Document Owner: D +ate of Last Update: 10/15/2013 #print $_; chomp; if( m/Date of Last Update:(.*)/) { print $1; next; } # Count the number of signature lines } close (IN); } } #print "dir is $dir\n"; } closedir(DIR); closedir(FILE); #print_data (\%hash); sub print_data { my ($h_ref) = @_; foreach my $dir (keys %$h_ref){ foreach my $file (keys $h_ref->{$dir}){ print "$dir, $file, $h_ref->{$dir}{$file}{UPLOAD_DATE} +\n"; } } }


Sample Document

Document #: 000 Version #: 1 Document Owner: Someone Date of Last Update: 10/15/2013 Written by: Someone Status: Approved General Description Purpose Definitions Procedures Sign-Off Approvals ______________________________________________________/_____/_____ Jane Doe, CEO Date ______________________________________________________/_____/_____ John Doe, CFO Date

In reply to How can I find a line in a RTF file? by kevyt

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.