Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done some extensive research about this problem and it seems that there is no work around because of the netframe work and OS set limit on address lengths. So my question is how can I exclude folders that exceed this limitation and simply move to the next file or folder when trying to scan directories?

thank you in advance :)
Posted
Comments
Sergey Alexandrovich Kryukov 10-Feb-11 21:48pm    
Again, no exception dump, no code. What kind of help are you hoping for?
--SA

You cannot have directory/file names in your system with the path name exceeding MaxPath. The exception could be a result of some bug during path calculation.

[EDIT]
File system names are valid it they are obtained using Directory.GetFiles or Directory.GetDirectories. These methods guarantee that the obtained names represent file system objects which "physically" present on the file system. Such name should always obey the name length limitation rules, otherwise they could not be created.

If the names are composed using some different method (which can easily happen if you need to compose a name to create new file/directory programmatically, the name could appear too long and cause this exception.
[END EDIT]

Please see my comment to the Question. Where is the information? This kind of bug is usually quite easy to find and fix.

—SA
 
Share this answer
 
v2
Comments
Dale 2012 10-Feb-11 22:26pm    
I have had no problem with the scanning code but I did have alot of desktop files folders and what not that i have catagorized into one folder which is how I know this error is authentic and deals with the max path exception but my question is how to skip folders and files with names exceeding this value?
Sergey Alexandrovich Kryukov 10-Feb-11 22:43pm    
As I say: something's must be wrong in your code. Why do you think you're posing right question? You think you need to skip something, but I say there should not be such thing. Post relevant part of your code and exception done! If you don't do that, there is nothing to discuss -- just yet.
--SA
Dale 2012 11-Feb-11 1:05am    
Ok the Exception is:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

and the line on error is:

Dim fi As FileInfo = New FileInfo(file1)
Dale 2012 11-Feb-11 1:07am    
can we now discuss the problem or is there something I need to add?
Sergey Alexandrovich Kryukov 11-Feb-11 12:37pm    
1) Are you sure exception was caused by this exact line? (You did not do exception dump as I asked. In exception dump you could print exception stack (highly recommend) and the stack would show all relevant line numbers in the code.)

2) Are you sure the string value of the variable "file1" represent existing file? Please see my update in this Answer, between [EDIT] and [END EDIT]

--SA
Typically, the single most common reason why recursive searches of hard disks fail is when certain directories require permissions that the calling code does not have.

Update
~~~~~~~~

Okay, unfortunately the classes in System.IO do not use Unicode paths (where you prefix "\\?\" to the path). You can avoid using System.IO and instead P/Invoke the API directly and use the W versions of the functions (and then use Unicode paths).

Example article that does this:
.NET 2.0 Workaround for PathTooLongException[^]
Although the article explains a different API, you will need to do something similar.

Alternatively, just skip files that exceed the max-path (but I reckon you will end up skipping too many files if you go that route). The hardcoded value for MaxPath in System.IO is 260 (Windows ANSI filepath limit).
 
Share this answer
 
v2
Comments
Dale 2012 10-Feb-11 22:20pm    
a good answer but I am most positive that the problem is not related to access denied. The exception clearly states a maxpath exception but thank you for the insight.

I will still rate your answer
Nish Nishant 10-Feb-11 22:25pm    
Do you mind pasting the exact text of the error message?
Dale 2012 10-Feb-11 22:42pm    
I will need one min to get this for u brb
Nish Nishant 10-Feb-11 22:43pm    
Ok, thanks.
Dale 2012 10-Feb-11 23:01pm    
Ok the Exception is:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

and the line on error is:

Dim fi As FileInfo = New FileInfo(file1)
Hello,


you can also try for this solution:-


you simply need to copy your project folder from your path to root directory (ex:-d:\abc\abc\xyz\YourProject to d:\YourProject )


Maximum file path length Error Solved.this trick work in my case.

thank you
 
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