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

Posted on 2004-11-10
Last Modified: 2010-04-17
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 ??


Question by:rab54
    LVL 2

    Expert Comment

    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:
    LVL 1

    Expert Comment

    Is that perl?
    If so, is it a requirement that the solution be in perl?

    Author Comment

    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

    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 .....




    Author Comment

    OK Sorted -

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

    cheers all


    Accepted Solution

    PAQed with points refunded (125)

    Community Support Moderator

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    lucky13 challenge 11 96
    post4 challenge 28 70
    count8 challlenge 13 68
    drawing animated level bar based on numbers 3 43
    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now