A novice (newbie) in need of help

J

jbl

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'
 
G

Gunnar Hjalmarsson

jbl said:
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.
 
J

Joe Smith

jbl said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top