Hi Greg,

        Front slashes as directory separators should work on Windows too (at
least, they do for me on WinXP).  Windows should accept front or back
slashes, Unix should accept only front slashes... so using front-slashes on
any platform as your directory separator should work.

=====
#!c:/program files/activestate/active_perl_v5.8.0.805/bin/perl
use strict;
use warnings;
my $filename;
print "Enter a filename:  ";
chomp ($filename = <STDIN>);
if (-e $filename) {
        print "$filename exists!\n";
} else {
        print "$filename doesn't exist!\n";
};
=====
Running the script above (named exists.pl) from the Windows XP command line:

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  ./exists.pl
        ./exists.pl exists!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  ../My Documents/Web Content/index.htm
        ../My Documents/Web Content/index.htm exists!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  ../My Documents/Web
Content/file_which_doesnt_exist.txt
        ../My Documents/Web Content/file_which_doesnt_exist.txt doesn't
exist!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  c:/documents and
settings/a248567/a_file_which_doesnt_exist.txt
        c:/documents and settings/a248567/a_file_which_doesnt_exist.txt
doesn't exist!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  c:\documents and
settings\a248567\a_file_which_doesnt_exist.txt
        c:\documents and settings\a248567\a_file_which_doesnt_exist.txt
doesn't exist!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  ..\My Documents\Web
Content\file_which_doesnt_exist.txt
        ..\My Documents\Web Content\file_which_doesnt_exist.txt doesn't
exist!

C:\Documents and Settings\A248567\Desktop>exists.pl
        Enter a filename:  ..\My Documents\Web Content\index.htm
        ..\My Documents\Web Content\index.htm exists!

----------
Kevin B. Pease          FISC - SCME
Fidelity Investments Systems Company
[EMAIL PROTECTED]       (617) 392-9022
SkyTel Page:  1-800-759-8888, Pin # 4713841
PACE group:  SCME


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 01, 2003 12:12 PM
To: mongers of perl
Subject: [Boston.pm] generic file system?


is there a generic file system interface
for perl?

this:==> (-e './subdir/file.ext')

works fine on Linux, but I'd have to 
        s{/}{\}g  
to get it to work on windows.

how do you write code that will work 
on both file systems without a lot of
        if($nix) {blah/blah;}
        else {blah\blah;}

I have a perl application I wrote for
windows that I'd like to pull over to
linux. If I do the work, I'd like to
rewrite it so it works on both sides.

Greg
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to