tags:

views:

568

answers:

3

in my previous question as follows:

"How to create a copy of a file having length more than 260 characters."

I have asked almost same qustion and I got a solution to rename the directory name and then copy to a new location. But as per the client's requirement we can't rename the directiory in any case.

So now my problem is when we try to copy a file having path length( including file name) more than 260 characters let say 267 characters, it allows as us copy manually but throws exception programmetically in vista OS.

Please suggest me if any one of have any solution.

Thank you.

A: 

You could check if compression tools like 7zip are limited by the length of the path in Vista.

If not, that means a "copy by program" would by:

  • compressed the tree of directories/file you want to copy
  • copy the .zip/.rar to the destination
  • uncompress
VonC
+1  A: 

If the problem is just with the length of the file (not the preceding path), then you can use the short name version of the file (probabaly Outloo~1.xls ).

However, the only real viable solution is to use network redirection or SUBST command to shorten the path. I can imagine that you'd have to be keeping track of the path length in your program, and spawn a SUBST drive letter when the length is exceeded... dropping the drive letter when it's no longer needed. Ugly programming, but no hope.

Or

I know some unicode version of windows api functions (copyfileex..? http://msdn.microsoft.com/en-us/library/aa363852(VS.85).aspx) can handle to 32,767 chars.

Try to name it with a \\?\ prefix, for example, \\?\D:\. I'm not sure if CLR uses this kind of naming style, but you can give it a try.

lakshmanaraj
SO has collapsed your double-backslashes to a single backslash -- either wrap them in `backticks` to "codify" them, or double them again.
j_random_hacker
ok edited the same.
lakshmanaraj
As per your suggestion, I have written the API function CopyFile passing file path with pre-pending "\\?\" but I am not getting any output even though it is not showing any error. Please suggest...
Suman
Please check your file naming convention via http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspxAlso check for copyfileEx.It may help.
lakshmanaraj
+3  A: 

Prepend \\?\ to your path to enable path lengths up to 32767 characters long. E.g:

copy \\?\C:\big\dir\hierarchy\myfile.txt \\?\C:\tohere.txt

This page has more details.

I've only tested this with DIR in WinXP, but that seems to work.

j_random_hacker