I am creating a Windows Forms application to copy folders without losing metadata such as creation and modification dates. It works fine when transferring files between my computer, flash drives, and external hard drives, but fails to work when I try to copy files off of my phone connected over a USB cable.
Using the suggestion in this post, I have tried using the shell32 library to get the path to the device by using Shell.BrowseForFolder
instead of Forms.FolderBrowserDialog.ShowDialog
. Sadly, this breaks the rest of my program by introducing invalid characters into the path: ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_04e8&pid_6860&ms_comp_mtp&samsung_android#6&fee689d&3&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SID-{20002,SECZ9519043CHOHB01,63829639168}\{013C00D0-011B-0130-3A01-380113012901}
This introduces invalid path errors when using DirectoryInfo
, File.Copy
, and Directory.EnumerateFiles
.
private void PickSourceButton_Click( object sender, EventArgs e )
{
int hwnd = 0;
Folder folder = shell.BrowseForFolder( hwnd, SourceFolderPicker.Description, 0, 0 );
if( folder != null )
SourceFolderTextBox.Text = ( folder as Folder3 ).Self.Path;
}
Short of rewriting the entire program to use Shell32.NameSpace
and FolderItem
, I do not know if there is another way to accomplish what I am trying to do. I am hoping that there is a way to translate this cryptic path into something more traditional.