0

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
JeremyEastham
  • 177
  • 2
  • 11
  • ^^This is for a UWP app. I am using Windows Forms. Can I still use these classes and methods? – JeremyEastham Jul 24 '19 at 23:34
  • I don't see a WinForms tag on your question. Missed it in the first sentence - you should add the tag. It doesn't appear that it's available in WinForms. Good thing I only posted a comment instead of an answer. :-) – Ken White Jul 24 '19 at 23:37
  • Does a DOS command work in copying a file? eg `xcopy sourcePath destinationPath /O /X /E /H /K` Can you see the removable drive by `foreach (DriveInfo drive in DriveInfo.GetDrives()) { if (drive.DriveType == DriveType.Removable) { Console.PrintLine(dirve.Name); } }` ? – Jeremy Thompson Jul 25 '19 at 01:21

0 Answers0