Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Am adding just a "kobo" suggestion, using your OP and the modification provided by ww to your script.

Anonymous Monk says:
"..D:\Prog\Perls is the location where I execute my code.."

In that case, you can get your desired result using chdir. {Updated}
Like so:

#!/usr/bin/perl use warnings; use strict; use File::Spec; my $dirname = "C:\\Users\\Me\\Desktop\\Cluster1"; my @file_to_use_later; ## for use later chdir $dirname; ## add this to OP script opendir DIR, $dirname or die "can't open directory: $!"; my @FILES = readdir(DIR); foreach my $FILE (@FILES) { my $fil_path = File::Spec->rel2abs($FILE); print "File path:", $fil_path, $/; push @file_to_use_later, $fil_path if -f $fil_path; ## check fi +les contents later } closedir DIR or die "can't close directory: $!"; ## test the files stored in the array variable later for my $filename (@file_to_use_later) { print $filename, $/; open my $fh, '<', $filename or die "can't open: $!"; while (<$fh>) { chomp; print $_, $/; } close $fh or die "can't close file:$!"; }

Also, take note of this important info from File::Spec documentation about the "rel2abs".
rel2abs() Converts a relative path to an absolute path.
$abs_path = File::Spec->rel2abs( $path ) ; $abs_path = File::Spec->rel2abs( $path, $base ) ;
If $base is not present or '', then Cwd is used. If $base is relative, then it is converted to absolute form using rel2abs(). This means that it is taken to be relative to Cwd.

On systems with the concept of volume, if $path and $base appear to be on two different volumes, we will not attempt to resolve the two paths, and we will instead simply return $path .

The above explain, why you are getting this:
D:\Prog\Perls\doc.txt D:\Prog\Perls\volt.txt D:\Prog\Perls\holiday.txt
instead of this
C:\Users\Me\Desktop\Cluster1\doc.txt C:\Users\Me\Desktop\Cluster1\volt.txt C:\Users\Me\Desktop\Cluster1\holiday.txt
Update:
You may also want to look into the module Path::Class and it's "cousins".
Path::Class 'just' is a "wrapper" for File::Spec.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: How to get full path name in windows? by 2teez
in thread How to get full path name in windows? by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2014-09-21 07:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (167 votes), past polls