Link to home
Start Free TrialLog in
Avatar of rab54
rab54

asked on

How to find if a file exists on windows .... ?

Hi gurus -

OK I am using File::Find to check a directory for files - but I want to give an error if there are no files there -

The problem is I get $file = . - regardless of whether there is a file there or not !

I have  tried using -e ...

any ideas guys ??

cheers

 Rab
Avatar of kjayaraman
kjayaraman

I think you can find the number of files in the directory to check if there are any files.

Use this link for more info:
http://www.codeguru.com/forum/showthread.php?t=312458
Is that perl?
If so, is it a requirement that the solution be in perl?
Avatar of rab54

ASKER

The link above isn't in perl - but it is perl that I need ....

Anyway after further investigation - the problem is differentiating between the CWD (eg '.' ) and actual filenames -

If I loop thro all the files I get
.
..
test.txt

I need to say if it is '.' or '..' (without quotes ;~)  - then give me a error message -
I have tried reg exes and also code like -

if (($file ne ".") || ($files ne "..") - blah

But none of it seems to work ....

any ideas would be great .....

cheers

 rab






Avatar of rab54

ASKER

OK Sorted -

As . and .. are always present - it means if the count is < 3 there is no file !

cheers all

rab
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial