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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:



Aug 31, 2000, 10:37 AM

Post #1 of 2 (254 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


Aug 31, 2000, 4:10 AM

Post #2 of 2 (254 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";

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\";

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