Absolute paths with multiple volumes

D

Donald

I am writing a simple perl program that is normally called from the command
line with a filename as an argument. I need the full absolute path and name
for this file. It is for WIN32 system that has multiple volumes (ie C: D:)

Examples
c:\myarea>myscript fred
-----> c:\myarea\fred

c:\myarea>myscript d:fred
-----> d:\current_directroy_of_volume_D\fred

I am new to perl but have searched extensively for a SIMPLE solution. It
seems to be a straightforward enough task and I am wondering whether I am
missing something obvious.

The file in question will always exist and has a file handle if that helps.

Regards


Donald.
 
R

Roel van der Steen

I am writing a simple perl program that is normally called from the command
line with a filename as an argument. I need the full absolute path and name
for this file. It is for WIN32 system that has multiple volumes (ie C: D:)

Examples
c:\myarea>myscript fred
-----> c:\myarea\fred

c:\myarea>myscript d:fred
-----> d:\current_directroy_of_volume_D\fred

#!perl
use Cwd 'abs_path';
use File::Spec;
($vol, $dir, $file) = File::Spec->splitpath('d:fred');
print File::Spec->catfile( abs_path("$vol$dir"), $file );

Cheers, Roel van der Steen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top