469,622 Members | 2,182 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

Path Too Long Problem MAX_PATH = 260 Chars kernel32.dll

This is a continuation the following post:

http://www.thescripts.com/forum/thread659736.html

The code I'm looking at is here, in the Finding Files and Directories part:

http://blogs.msdn.com/bclteam/archiv...-hamilton.aspx

I've gotten the code to run, but it crashes on the following line:

found = FindNextFile(findHandle, out findData);

It mostly fails when a long filename is passed into it, for example: thisisareallylongfilename.txt

Where simple.txt works fine.

Anyone know why this happens?

Thanks
Jul 27 '07 #1
9 3542
TRScheel
638 Expert 512MB
After reading that, it seems that FindFilesAndDirs assumes that the \\?\ switch is passed. If it isnt, it will run into the same roadblocks as the normal methods of finding files and directories.

Are you passing in file names with '\\?\' prepended?
Jul 27 '07 #2
Yes, I've changed their version around a little.

public static List<string> FindFilesAndDirs(string dirName)
{
dirName = @"\\?\" + dirName;
...
}

btw, the error that I'm getting is "...Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack..."

Does this help?

After reading that, it seems that FindFilesAndDirs assumes that the \\?\ switch is passed. If it isnt, it will run into the same roadblocks as the normal methods of finding files and directories.

Are you passing in file names with '\\?\' prepended?
Jul 27 '07 #3
TRScheel
638 Expert 512MB
Yes, I've changed their version around a little.

public static List<string> FindFilesAndDirs(string dirName)
{
dirName = @"\\?\" + dirName;
...
}

btw, the error that I'm getting is "...Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack..."

Does this help?
The call to that function is recursive. You need to prepend that outside the function, not within. At least, thats my take on it. If you look within the if / else block of the do / while (found) loop, it calls itself. In that call to itself it has:

Expand|Select|Wrap|Line Numbers
  1. Path.Combine(dirName, currentFileName);
if dirName has the '\\?\' within it, and is passed to the function, you prepend it again. I am not sure if that is cause for error or not though. A simple fix would be to instead at the beginning of the function write:


Expand|Select|Wrap|Line Numbers
  1. dirName = dirName.StartsWith(@"\\?\") ? dirName : @"\\?\" + dirName;

On an aside, please read up about CODE tags. They are used as such:

{code=VALUE}... code within here ... {/code}

Where { and } are replaced with [ and ] respectively. VALUE can be omitted and you can just have {code} (again, replace { } ) or VALUE can be:

cpp
vbnet
html

And many more that are not coming to mind at the moment. For C#, cpp is most appropriate
Jul 27 '07 #4
I'd like to say that helped, but it doesn't seem to be the case. After further research I'm pretty sure the problem has something to do with kernel32.dll. I've noticed that the code *sometimes* works. I use the same starting directory each time, and sometimes it successfully navigates through it, and sometimes it breaks. Here is the error when it breaks:

"FatalExecutionEngineError was detected

The runtime has encountered a fatal error. The address of the error was at 0x79e8a634, on thread 0x7e8. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."

One of the recommendations to solve this problem is to completely remove Visual Studio and reinstall a version with the latest updates. Other fixes I've heard of involve how my environment is setup (managed, native, etc.)

I've also read that this error is going to be resolved with the next VS update..


The call to that function is recursive. You need to prepend that outside the function, not within. At least, thats my take on it. If you look within the if / else block of the do / while (found) loop, it calls itself. In that call to itself it has:

Expand|Select|Wrap|Line Numbers
  1. Path.Combine(dirName, currentFileName);
if dirName has the '\\?\' within it, and is passed to the function, you prepend it again. I am not sure if that is cause for error or not though. A simple fix would be to instead at the beginning of the function write:


Expand|Select|Wrap|Line Numbers
  1. dirName = dirName.StartsWith(@"\\?\") ? dirName : @"\\?\" + dirName;

On an aside, please read up about CODE tags. They are used as such:

{code=VALUE}... code within here ... {/code}

Where { and } are replaced with [ and ] respectively. VALUE can be omitted and you can just have {code} (again, replace { } ) or VALUE can be:

cpp
vbnet
html

And many more that are not coming to mind at the moment. For C#, cpp is most appropriate
Jul 30 '07 #5
I was trying to figure out on how to use that unicode functions, spent lots of time on this and finally bought SDK to handle it at <link removed>
Aug 27 '08 #6
I was trying to figure out on how to use that unicode functions, spent lots of time on this and finally bought SDK to handle it at <link removed>
<link removed again>
Aug 28 '08 #7
Curtis Rutland
3,256 Expert 2GB
Please don't reopen a thread from a year ago just to post a link to a product. I can see that this product is relevant to the thread, but it is still considered spamming.

MODERATOR
Aug 28 '08 #8
You can try "Long Path Tool" program.
Oct 20 '13 #9
try using long path tool for this
May 26 '14 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by mtech1 | last post: by
3 posts views Thread by Zenu | last post: by
6 posts views Thread by Lubomir | last post: by
5 posts views Thread by Martin Carpella | last post: by
5 posts views Thread by =?Utf-8?B?SmVmZiBCZWVt?= | last post: by
4 posts views Thread by Tim Cook | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.