Copy a file to a long directory gives error

Jan 5, 2014 at 5:48 PM
Hi,

I love this project, but :

When I try to copy a file to a long path (>255 chars) and it gives an error.
Example :

using Alphaleonis.Win32.Filesystem;

private void button1_Click(object sender, EventArgs e)
{
string s1 = @"c:\tmp";
string s2 = "\\aaaaaaaaaaaaaaaaaa01\\aaaaaaaaaaaaaaaaaa02\\aaaaaaaaaaaaaaaaaa03\\aaaaaaaaaaaaaaaaaa04";
     string s3 = "\\aaaaaaaaaaaaaaaaaa05\\aaaaaaaaaaaaaaaaaa06\\aaaaaaaaaaaaaaaaaa07\\aaaaaaaaaaaaaaaaaa08";
     string s4 = "\\aaaaaaaaaaaaaaaaaa09\\aaaaaaaaaaaaaaaaaa10\\aaaaaaaaaaaaaaaaaa11\\aaaaaaaaaaaaaaaaaa12";
     string destDir = s1 + s2 + s3 + s4;
     Directory.CreateDirectory(destDir);

     string destFile = "123456789012345678901234567890.txt";
     string destPath = destDir + "\\" + destFile;       // Total size = 293 chars
     bool success = File.Copy("c:\\tmp\\vvv2.txt", destPath);   // Gives error
  }
It seems that NativeMethods.CopyFileEx() in the File.CopyMoveInternal method uses the normal paths (sourcePath, destinationPath) instead of the long ones (sourcePathLp, destinationPathLp).
Changing this resolves the error.

Could you please fix this ?
Jan 5, 2014 at 8:37 PM
This is a documentation scarce syndrom.

To work with long paths you should explicitly use Path.Getlongpath method before supplying long paths to IO methods. This is done to make code developers aware what they are dealing with and be careful with long paths as majority of other software cannot work with them.



Developer
Jan 5, 2014 at 8:48 PM
Hi, thanks for reporting.

Good catch! Will fix this.

Regards,
Yomodo
Developer
Jan 5, 2014 at 8:50 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Marked as answer by Yomodo on 1/6/2014 at 3:25 PM