I'm having some issues on moving a file, that has been written using another software's API, to a path that is very long.
The destination path is created using
Dim path As String = "\\?\C:\Basedir\Long-path-base"
For Each folderName As String In pathList
currentPath = IO.Path.Combine(currentPath.Trim(), folderName.Trim())
CreateDirectoryW(currentPath.Trim(), IntPtr.Zero)
Next
As you can see, I'm using CreateDirectoryW due to the >256 character path. pathList is a simple List(Of String) with foldernames corresponding to the final path for the current file.
with pathList = {'folder1','folder2',folder3','....'} the path will then be
C:\Basedir\Long-path-base\folder1\folder2\folder3....
The above works very well. The problem comes when I want to copy the file that has been written to My.Computer.FileSystem.SpecialDirectories.Temp to currentPath. The file is written nicely to the temp-directory, but not moved to the path above.
I do:
Dim sourceFile As String =
My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.Temp, filename & ".ddb")
Dim destinationFile As String = My.Computer.FileSystem.CombinePath(path, filename & ".ddb")
Dim success As Boolean = MoveFileW(sourceFile, destinationFile.Remove(0, 4))
One thing I don't understand is if I should have "\\?\" added to the sourcepath, or removed from the destinationpart (as is done above). I have tried both, but without success. The reason why I'm not writing the file to the destinationfolder directly is that the API does not support path's longer than 256 characters.
I'm using .NET 4.7.2
Any help would be great!