That would be a negative. Been there, done that.
Still run into "PathTooLongException"
"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."
As indicated above, the path is greater than the maximum allowed 260 characters. This problem is caused by shares and mappings. Once a share is mapped, Windows allows users to create paths exceeding 260 characters.
a server path of "E:\User Drives\Home Directories\Divisions\User.Name" gets mapped to each user's H-Drive or "H:\".
The user of course has full control over their home drive.
Because each user's share is mapped to a drive letter, their built-in Windows File path begins at 3 characters - "H", ":" and "\"
They are allowed a path of 257 additional characters (and they have used every bit of it in many cases)
So, from the user's point of view, they are within their rights to create folders and files. But from the server's point of view there is an extra 48 characters (give ot rake pending the length of the Division and the length of the user's name) taxxed onto the file paths. So if a user creates a path that is only 240 characters, when the server views it, it's over 288 characters.
The Visual Basic Object does not compensate.
Microsoft.VisualBasic.Devices.Computer comp = new Microsoft.VisualBasic.Devices.Computer();
comp.FileSystem.CopyDirectory(strSource, strDestination);
I did discover that using old school DOS 8.3 path and filename truncation DOES work.
For instance:
I can remap a drive based on 8.3 Truncation "..\LongFo~1\" mapping the destination in the same manner and the files copy flawlessly.
So far, things that do not work:
xCopy
C# System.IO
VB FileSystem
Attempting to use API calls to share a folder, then map to that new share (the server path to share a directory is subject to the same 260 character limitations)
But it was a nice attempt.
What has worked ...
Map a Drive to the Share needing to be copied.
When PathTooLongException is thrown, Truncate the path to DOS 8.3 Short Path name
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
);
using
[DllImport("Netapi32.dll")]
private static extern uint NetShareAdd(
[MarshalAs(UnmanagedType.LPWStr)] string strServer,
Int32 dwLevel,
ref SHARE_INFO_502 buf,
out uint parm_err
);
Share the DOS 8.3 short file name
Map to the newly created Share
Continue the File Copy
Disconnect the Mapped Drive
Delete the Share
Continue to the next Directory