Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Dot and Dubble Dot directory names
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


Report this thread to moderator Post Follow-up to this message
Old Post
Tony Frasketi
08-27-05 02:55 AM


Re: Dot and Dubble Dot directory names
> 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

Report this thread to moderator Post Follow-up to this message
Old Post
JupiterHost.Net
08-27-05 02:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:46 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.