Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I adapted a piece of code (recursive LINQ query) to generate a BindingList(of FileInfo) over a LAN. That works well on a local computer, and it seems to be fine on most of the remote network computers, too.

There seems to be a problem with the query, I guess, since I eventually get error message that "A part of the network path could not be found". This appears odd considering that the query reads paths first – and then can't find then...

(EDIT: I've checked that the path's throwing an error are existing and there's also no security issue with them. It must be something in the code)

In my strong believe that Alzheimer's wouldn't spread to Computers: Can someone please help me clear up the confusion as well as, if needed, correct the syntax?

Thank you very much,
Kind regards
Michael

What I have tried:

VB
Try
    For Each result As FileInfo In dirInfo.GetFiles(pattern).Select(Function(file) file).Where(Function(s) supportedExtensions.Contains(Path.GetExtension(s.Extension).ToLower()))
        queue.Enqueue(result)
        report(dirInfo.FullName)
    Next result
    Task.WaitAll(dirInfo.GetDirectories().Select(
     Function(d) Task.Factory.StartNew(
       Sub() InternalCollectFiles(d, pattern, queue))).ToArray())

Catch e As UnauthorizedAccessException
Catch e As SecurityException
Catch e As DirectoryNotFoundException
    MsgBox(String.Format("Error: {0}", e.Message))

Catch ex As Exception
    MsgBox(String.Format("Error in 'InternalCollectFiles': {0}", ex.Message))

End Try
Posted
Updated 4-Feb-19 22:07pm
v2
Comments
F-ES Sitecore 4-Feb-19 7:01am    
When the error occurs see what path it is trying to access. Either the path is wrong as there is a code issue, or the path is correct but can't be accessed due to a security issue. We don't have access to your system or your network so we can't check these things for you.
Sonhospa 4-Feb-19 7:09am    
Did you read it? It's a completely different question, not a repost.
Maciej Los 4-Feb-19 7:17am    
Yeah, i've read that twice. The only differ is that you did not mention (in your previous question) that above code generates such of error message...
Sonhospa 4-Feb-19 7:29am    
1. Looking for approach to extend a LINQ query
2. Trying to resolve a DirectoryNotFoundException

Completely different tasks. Have a (more) beautiful day.

1 solution

Accordingly to the discussion in comments, there's few issues with your code, which may cause A part of the network path could not be found error. Conclusion is: you have to change a method you get files and folders information. Quite good explanation how to achieve that is here: c# - Asynchronously Enumerate Folders - Stack Overflow[^]

Additionally i'd suggest to read below articles too:
How to: Iterate File Directories with the Parallel Class | Microsoft Docs[^]
A Faster Directory Enumerator[^]
Enumerating Files and Directories in VB 2010[^]
c# - Improve the performance for enumerating files and folders using .NET - Stack Overflow[^]
c# - Get all files and directories in specific path fast - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900