The following method overwrites the Windows API and allows you to move a folder or directory if its path is over 260 characters:
Note: Replace "H:\Calvin\kernel32.dll" with the path to kernel32.dll (can be found in your system32 folder)
Note2: You can call Move on a directory or file
[DllImport(@"H:\Calvin\kernel32.dll", CharSet = CharSet.Unicode)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool MoveFile(string lpExistingFileName, string lpNewFileName); public static void Move(string fileName, string toPath) { string formattedName = @"\\?\" + fileName; MoveFile(formattedName, toPath); }
If you have the problem where you don't the exact path you want to retrieve because you can't access it in the first place, ABTO created a nice little DLL that helps you with paths that are too long. The trial version has enough functionality to work. Download it HERE.
If you want to do other functions besides move a file, check out the File Management Functions documentation and alter the above code.
References:
Kim Hamilton
0 comments:
Post a Comment