#!/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 files 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:$!";
}
####
$abs_path = File::Spec->rel2abs( $path ) ;
$abs_path = File::Spec->rel2abs( $path, $base ) ;
####
D:\Prog\Perls\doc.txt
D:\Prog\Perls\volt.txt
D:\Prog\Perls\holiday.txt
####
C:\Users\Me\Desktop\Cluster1\doc.txt
C:\Users\Me\Desktop\Cluster1\volt.txt
C:\Users\Me\Desktop\Cluster1\holiday.txt