A novice (newbie) in need of help

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

  1. jbl

    jbl Guest

    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
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Dec 15, 2004
    #2
    1. Advertising

  3. jbl

    Joe Smith Guest

    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
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Buttercup
    Replies:
    2
    Views:
    377
    Will Stuyvesant
    Sep 21, 2003
  2. Gates Danderhoff
    Replies:
    2
    Views:
    338
    David Dorward
    Mar 17, 2006
  3. AMT2K5
    Replies:
    15
    Views:
    587
    Victor Bazarov
    Jul 17, 2005
  4. Replies:
    9
    Views:
    326
    Pascal J. Bourguignon
    Aug 1, 2008
  5. mtait
    Replies:
    2
    Views:
    139
    mtait
    Sep 25, 2006
Loading...

Share This Page