Spencer_Lists wrote:
> Greetings perl-win32-users,
>
> This is not a strictly win32 question but relates to files in a win32
> system so ...
>
> The context is pretty obscure so I am including the very minimum code
> snippet. @files is an array of all the files in the path folder. I
> need to check whether the file $newname exists in the path folder. An
> odd situation came up with a file named "blah blah blah (1940.mid"
> The author of the file forgot the closing ) which is fine for a
> windows file name but grep sees the "(" as missing the ")" in a regex.
> I have tried quoting and preceding the ( or ) with \ to escape it but
> none of this works. Any ideas? I could also just check the folder for
> the presence of the file name but I have never found documentation on
> how to do this. Since this would be more of a win32 question, maybe
> that is what I should be asking. How do I check for the existence of a
> file in a folder?
>
> my @files = <$path/*>;
> my $file_exists = 1 if (grep/$newname/,@files);
Again - supply a complete failing snippet - I added the \Q .. \E
operators to keep the '(' from being interpolated (you could also
qr{} the $newname instead) :
use strict;
usse warnings;
my @files = ('blah blah blah (1940.mid', );
my $newname = '(1940';
my $file_exists = 0;
$file_exists = 1 if grep /\Q$newname\E/, @files;
print "file_exists = $file_exists\n";
__END__
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs