>This works for me:
Dim loDirectoryInfo As System.IO.DirectoryInfo
> loDirectoryInfo = New System.IO.DirectoryInfo("d:\\tmp")
>
> For Each loFile In loDirectoryInfo.GetFiles()
> Dim l As Long = loFile.Length
> Console.WriteLine("Name: {0} Length:{1}", loFile.FullName, loFile.Length)
> Next
Also you said the error was 'could not find file' - seems odd that that would occur on the fourth reference to loFile rather than the first ?
The error message is a complete dummy one which has no reference to the real error. It says that but it is really in reference to the number of characters. So, the file object can be handled. But, when we access the Length property, it bugs.
I tried dumping loFile.Length into a Long and that is the same problem.
At first, I thought it was because the client entered a bunch of weird characters in the file name such as a comma, a pound sign and so on. I also found it quite weird that they chose such a long name. But, they are the client. So, we were trying to adapt the application to support such a long file name. But, later on, I found that it is about at that exact location. So, I changed the file name to something like 11111111111111111111111.pdf, where I would have 160 characters. Up to that, it worked. But, as soon as I had one more character, it bugs. I also tried with letters. It was the same situation.
It might be related to something on that drive. For now, there is a validation in my class to return a message about it instead of generating an error.