Hi there

I have a problem. When I try to open files found by File::Find they are not recongnized as files if they are located in a sub directory, and if the directory is pointed out as a relative path. Here is some code; I also post my test code so you can see what kind of tests I have made
use File::Find; use Getopt::Std; sub process_file { my $file_short=$_; my $file = $File::Find::name; return if ($file_short eq "test.pl"); print "file name $file_short\n"; print "long filename $file\n"; if (-f $file && -r $file) { open (INPUT, "<", "$file") or die "unable to open file $file bec +ause: $!"; } while ($line=<INPUT>){ print "$line \n"; } ### end of worki if (-f $file) { open (OUTPUT, ">c:\\temp\\merck_out\\$file_short.out") || die (" +Unable to openc:\\merck_out\\$file_short.out for writing exiting...") +; } } getopts('d:'); my $dir = $opt_d; print " dir $opt_d\n"; find(\&process_file, $opt_d); ### this one is working #open (INPUT2, '<./test_folder/forecast_debug.txt') || die ("Unable to + open .\merck_test\forecast_debug.txt for input reson $!"); #while ($line=<INPUT2>){ # print "$line \n"; #} ### end of working ### this one is working #open (INPUT2, '<.\merck_test\forecast_debug.txt') || die ("Unable to +open .\merck_test\forecast_debug.txt for input reson $!"); #while ($line=<INPUT2>){ # print "$line \n"; #} ### end of working ### this one is working as well #my $strFile2 = '.\merck_test\forecast_debug.txt'; #open (INPUT3, "<$strFile2") || die ("Unable to open $strFile2_debug.t +xt for input reson $!"); #while ($line=<INPUT3>){ # print "$line \n"; #} ### end of working ### works as well #my $strFile3 = "./merck_test/forecast_debug.txt"; #open (INPUT3, "<$strFile3") || die ("Unable to open $strFile3 for inp +ut reson $!"); #while ($line=<INPUT3>){ # print "$line \n"; #} ### end of working close INPUT; close OUTPUT; close INPUT2; close INPUT3
So... If I start this, in dir c:\temp with:
test.pl -d .
it will find all files under the current dir, but it can not open any file in a sub dir.
But... If I give an absolute path and start it like this:
test.pl -d 'C:\temp'
it will work, and will be able to open the files in the sub folder.
does any one have an idea or solution for this, because I really want to use relative path's in my function
Best regars

Pär

In reply to unable to open files in dirs retrived by File::Find by kurreburre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.