CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Directories...

 



KaoAtlantis
Novice

Aug 31, 2000, 10:37 AM

Post #1 of 2 (244 views)
Directories... Can't Post

I was wondering how to test if a Directory(In Windows) Exists...

I have been trying to figure this one out for awhile...

Thans for the Help, Kao


japhy
Enthusiast

Aug 31, 2000, 4:10 AM

Post #2 of 2 (244 views)
Re: Directories... [In reply to] Can't Post

Use the -e and -d file tests:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if (-e $path and -d _) {
print "$path is a directory.\n";
}
</pre><HR></BLOCKQUOTE>

The _ is a shortcut for saying "use the same variable I used last time" for the -X operators (see the perlfunc documentation).

CAVEAT SCRIPTOR: If you try saying

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$path = "C:\Windows\Desktop\test-1.pl";
</pre><HR></BLOCKQUOTE>

you will be quite unhappy, since in a double-quoted string, "\W" is "W", "\D" is "D" and "\t" is TAB. Workarounds include: using single quotes, backslashing the backslashes, or using forward slashes (this is the easiest and nicest).

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives