VB.Net file not found exception error.

Posted on 2006-04-27
Last Modified: 2012-06-21
when using the function below, on certain files, it will puke with an exception error saying file not found.  any ideas.

        Dim Size As Long = 0
        ' Add file sizes.
        Dim fis As FileInfo() = d.GetFiles()
        Dim fi As FileInfo
        Dim con As Console

        For Each fi In fis
                Size += fi.Length
            Catch er As Exception

            End Try

        Next fi

        ' Add subdirectory sizes.
        Dim dis As DirectoryInfo() = d.GetDirectories()
        Dim di As DirectoryInfo
        For Each di In dis
            Size += DirSize(di)
        Next di

        Return Size
    End Function 'DirSize
Question by:beaconlightboy
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You are making a recursive call to DirSize()....I think...

    Can you show us the declaration for DirSize as well?

        Public Function DirSize(....?
    LVL 3

    Author Comment

    yes.  its public function dirsize(byval d as directoryinfo) as long

    LVL 85

    Accepted Solution

    I did my entire C: drive (took quite ahwhile...) with no errors.   =\

    It came back with: 69921964800

    LVL 3

    Assisted Solution

    You may want to check the security settings of the files that are failing. If for instance you are not a local administrator of the machine and you are trying to access 'C:\Documents and Settings\SomeOtherUser' you may run into issues.

    I hope this helps :)
    LVL 3

    Assisted Solution

    I agree with pitster. It should be related to file permissions. Moreover, I suggest you turn off "Simple File Sharing" folder option.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    Title # Comments Views Activity
    post4 challenge 28 70
    wefewf 2 28
    strCount chalenge 3 34
    Looking for example pivot year code used in Y2K 4 12
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This article will show, step by step, how to integrate R code into a R Sweave document
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    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…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now