package PGF::Utilities::FileUtility; =head1 NAME PGF::Utility::FileUtility Module containing methods for file manipulations. =head1 VERSION $Revision: 1.3 $ $Date: 2009-08-26 17:18:40 $ =head1 SYNOPSIS =head1 DESCRIPTION =head1 AUTHOR(S) Stephan Trong =head1 HISTORY =over =item * Stephan Trong 11/03/2006 Creation =back =cut #============================================================================# use strict; use warnings; use Carp; use Carp qw(cluck); use File::Basename; use File::Find; use Cwd; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( fileNameWithIteration getRealPath ); our %EXPORT_TAGS = ( all=>[ qw( fileNameWithIteration getRealPath) ] ); #============================================================================# sub fileNameWithIteration { my $file = shift; my $extension = 1; while ( -e "$file.$extension" ) { $extension++; } return "$file.$extension"; } #============================================================================# sub getRealPath { my $filename = shift; my $dir = cwd; my $realPath = ''; find sub { return unless -1; my @right = split /\//, $File::Find::name; my @left = do { @right && ($right[0] eq "") ? shift @right : # quick way split /\//, $dir; }; # first element always null while (@right) { my $item = shift @right; next if $item eq "." or $item eq ""; if ($item eq "..") { pop @left if @left > 1; next; } my $link = readlink (join "/", @left, $item); if (defined $link) { my @parts = split /\//, $link; if (@parts && ($parts[0] eq "")) { # absolute @left = shift @parts; # quick way } unshift @right, @parts; next; } else { push @left, $item; next; } } $realPath = join("/",@left); }, $filename; return $realPath; } #============================================================================# 1;