Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > A novice (newbie) in need of help

Reply
Thread Tools

A novice (newbie) in need of help

 
 
jbl
Guest
Posts: n/a
 
      12-15-2004
I am an extreme novice but I can do simple things with examples.
The following is the first part of something I am working on. It
basically gets all filenames of PDF files in a path, input to the
command line.

It then calls pdftotext with the parameters, remove pagebreaks, the
target PDF file, the output file (in text subfolder). The target
filename is the same as the output filename except for the extension.

My problem is that while this works fine, I get the error messages
that I have included at the bottom of this message.

Any suggestions as to what I can do to prevent these errors?

Thanks
jbl

# command line input >pdflang2 C:\test_docs

use File::Basename;
fileparse_set_fstype("MSWin32");

# uses path to pdf files from command line argument
# ARGV[0] = C:\test_docs here

opendir (DIR,$ARGV[0]) || die "Couldn't open directory, !";
while ($file= readdir DIR){
($basename,$path,$extension) = fileparse("$ARGV[0]/$file",
qr{\.pdf});

# now I am calling pdftotext to extract the text from the PDF
# and save it as C:\test_docs\text\$basename.txt

system
("pdftotext","-nopgbrk","$path/$file","$path/text/$basename.txt");

}

close DIR;

My command line input:

D:\PerlScripts>pdflang2 C:\test_docs

I am getting the following error messages to the screen:

Error: Couldn't open file 'C:\test_docs//.'
Error: Couldn't open file 'C:\test_docs//..'
Error: Couldn't open file 'C:\test_docs//text'
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-15-2004
jbl wrote:
> My problem is that while this works fine, I get the error messages
> that I have included at the bottom of this message.
>
> Any suggestions as to what I can do to prevent these errors?


<snip>

Use grep() to exclude non-PDF files from the loop.

> while ($file= readdir DIR){


for my $file ( grep /\.pdf/, readdir DIR ) {

This group is defunct. Use comp.lang.perl.misc if you have further
questions.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      12-16-2004
jbl wrote:
> opendir (DIR,$ARGV[0]) || die "Couldn't open directory, !";
> system
> ("pdftotext","-nopgbrk","$path/$file","$path/text/$basename.txt");


That should be "$ARGV[0]/$path/$file".
-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Novice C++ programmer need help lilchiko1286@gmail.com C++ 9 08-01-2008 02:22 PM
DVD recorder novice need help Vic R DVD Video 1 06-02-2005 04:39 AM
wireless novice need help =?Utf-8?B?d2F5bmVyMTIzMTIz?= Wireless Networking 1 11-04-2004 01:34 PM
Complete novice - what do I need? Buttercup XML 2 09-21-2003 04:19 PM
novice i need help j.wright Digital Photography 1 09-10-2003 08:42 AM



Advertisments