# A novice (newbie) in need of help

Discussion in 'Perl' started by jbl, Dec 15, 2004.

1. ### jblGuest

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'

jbl, Dec 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.

--
Email: http://www.gunnar.cc/cgi-bin/contact.pl

3. ### Joe SmithGuest

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

Joe Smith, Dec 16, 2004