Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

File::Find Problem

by sivaramanm (Acolyte)
on Aug 11, 2006 at 05:31 UTC ( [id://566748]=perlquestion: print w/replies, xml ) Need Help??

sivaramanm has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I don't get result for spaced directory name when using File::Find. I have tried as below:

When I remove space in directory name, it is working

Thanks

Siva

use warnings; use File::Find; die ("\n\n\tsyntax: pdftotextscript <folder path>\n") if ($#ARGV != 0) +; my $root_dir = qq/"$ARGV[0]"/; find(\&fix, $root_dir); sub fix { return if ! /\.pdf?/i; system("c:\/Tools\/pdftotext.exe $_"); }

Replies are listed 'Best First'.
Re: File::Find Problem
by Samy_rio (Vicar) on Aug 11, 2006 at 05:44 UTC

    Hi sivaramanm, Use double quotes in argument of pdftotext.exe like this,

    system("c:\/Tools\/pdftotext.exe \"$_\"");

    Assign $ARGV[0] value to a variable directly as:

    my $root_dir = $ARGV[0];

    return if ! /\.pdf?/i;

    In the return statement, you made couple of mistakes, it should be

    return if !~ /\.pdf$/i;

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Re: File::Find Problem
by graff (Chancellor) on Aug 11, 2006 at 06:08 UTC
    If your directory name is something like  My Silly Folder Name (i.e. four words, three spaces), then you must put quotes around the full name on the command line when you run the perl script -- otherwise, the shell will pass the name to perl's @ARGV as four separate args (that is: @ARGV[0..3]).

    I guess another way to handle this (without qouting the directory name on the command line) might be:

    my $root_dir = join " ", @ARGV;

    In any case, your attempts at putting quotes around $ARGV[0] have no effect at all on the issue.

      I guess another way to handle this (without qouting the directory name on the command line) might be: my $root_dir = join " ", @ARGV;

      Until you pass a file named: two  spaces or a\ttab (replace "\t" with an actual tab). Any assumptions that the program makes as to the whitespace of unquoted parameters is just asking for trouble.

      --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://566748]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-09-16 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.