VB.Net file not found exception error.

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You are making a recursive call to DirSize()....I think...

Can you show us the declaration for DirSize as well?

    Public Function DirSize(....?
beaconlightboyAuthor Commented:
yes.  its public function dirsize(byval d as directoryinfo) as long

Mike TomlinsonMiddle School Assistant TeacherCommented:
I did my entire C: drive (took quite ahwhile...) with no errors.   =\

It came back with: 69921964800


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 :)
I agree with pitster. It should be related to file permissions. Moreover, I suggest you turn off "Simple File Sharing" folder option.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.