Code Comments
Programming Forum and web based access to our favorite programming groups.
In a program such as the following....
-----------------------------------------------------------------
#!/usr/local/bin/perl -w
$windir = "/home/users/tony";
opendir(NT, $windir) || die "no $windir?: $!";
while ($name = readdir(NT)) { # scalar context, one per loop
print "$name\n"; # prints ., .., system.ini, and so on
}
closedir(NT);
exit;
-------------------------------------------------------------------
$name returns each of the files in the given directory. To form the
absolute path of the files given by $name, you would simply combine the
$windir and the $name variables like so: "$windir/$name". For example
"/home/users/tony/x.txt".
My question relates to the two files '.' and '..'. Is there any function
that will give the absolute path of these directories when fed $name
values of '.' and '..' ? Without having to chdir to these directories,
that is.
I hope I've posed my question so as to be understandable...
I've looked online and in the O'reilly books but can't find the answer.
TIA
Tony Frasketi
Post Follow-up to this message> In a program such as the following....
> -----------------------------------------------------------------
> #!/usr/local/bin/perl -w
>
# always always always use strict and warnings!!!
use strict;
use warnings;
use File::Spec;
> $windir = "/home/users/tony";
my $windir = '/home/users/tony';
> opendir(NT, $windir) || die "no $windir?: $!";
"or die" not "|| die"
> while ($name = readdir(NT)) { # scalar context, one per loop
while(my $name...
or better yet:
while(readir NT) {
my $abs = File::Spec->rel2abs($_);
print "$abs\n";
}
> print "$name\n"; # prints ., .., system.ini, and so on
> }
> closedir(NT);
> exit;
exit not needed
> -------------------------------------------------------------------
> $name returns each of the files in the given directory. To form the
> absolute path of the files given by $name, you would simply combine the
> $windir and the $name variables like so: "$windir/$name". For example
> "/home/users/tony/x.txt".
>
> My question relates to the two files '.' and '..'. Is there any function
> that will give the absolute path of these directories when fed $name
> values of '.' and '..' ? Without having to chdir to these directories,
> that is.
perldoc -f File::Spec
HTH :)
Lee.M - JupiterHost.Net
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.