Title: RE: Verify file exists
I think I am having problems with reading the text file and then processing the actual path ...
 
The following is the content of the file
 
system.txt
===========
 
\\m1\main\testing\file.txt
\\m1\main\testing\file1.txt
 
if I replace the '\' character to '/' using s|\\|/|gi the file is never found.
 
If I manually type in the file and then replace then the file is existent:
 
$val="\\\\m1\\main\\testing\\file.txt"
$val=~s|\\|/|gi;
 
if (-e "$val")
{
    print "File exists\n";
 }
   else
{
    print "file doesn't exist\n";
}
 
Any more thoughts on the issue would be welcome.
 
Thanks

 
-----Original Message-----
From: Peter Vogel [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 16, 2000 9:59 AM
To: Roee Rubin; Perl-Win32-Users Mailing List
Subject: RE: Verify file exists

Also, if you don't know how big system.txt is
gonna be, you might want to recode like this:

open(INF, "system.txt) || die "Could not open system.txt: $!\n";
while ($val = <INF>) {
    ...
}
close(INF);

That way you aren't sucking the entire contents
of a file into memory for no good reason...

Things also become a little more readable if you
take advantage of the default operand $_:

while (<INF>) {
        chomp;
        s|\\|/|g;  # use | instead of # because # is for comments
        print "$_ - exists\n" if (-e $_);
}

-Peter
 

---
Peter A. Vogel
Manager, Engineering Operations
iReady Corporation
http://www.iready.com; http://www.iready.net


> -----Original Message-----
> From: Roee Rubin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 16, 2000 9:28 AM
> To: Perl-Win32-Users Mailing List
> Subject: Verify file exists
>
>
> Hello,
>
> I am trying to verify if a file exists on a network drive
> (\\drive\volume\etc).
>
> The name of the files I am trying to verify are located in a
> text file, and
> are written in the above format.
>
> The following code does not seem to work ...
>
> open (INF, "system.txt"); #read file
>       @file_txt=<INF>;
> close(INF);
>
> foreach $val (@file_txt) {
>       chomp($val);
>       $val=~s#\\#/#gi;  # replace '\' with '/'
>       ($exist)=stat($val);
>       if ($exist) {
>               print "$val - exists";
>       }
> }    
>
>
> your help is appreciated .
>
>
> Roee Rubin
> [EMAIL PROTECTED]
>
>
> ---
> You are currently subscribed to perl-win32-users as:
> [EMAIL PROTECTED]
> To unsubscribe, forward this message to
>          [EMAIL PROTECTED]
> For non-automated Mailing List support, send email to 
>          [EMAIL PROTECTED]
>

Reply via email to