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