1

I am trying to get a list of files from my samsung phone when plugged in via usb on the computer. the code below return file not found exception due to part of path not found. However, the source path can be found on the file explorer.

string source = @"SAMSUNG\Phone";
DirectoryInfo dir = new DirectoryInfo(source);

dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

Example of how the cellphone device display look similar to this:

Example: screenshot of file explorer

The error message listed my project name path\SAMSUNG\phone, which is weird. I tried this with regular USB thumbdrive that have an actual drive name and it works. Any advice help. Thank you!

posh
  • 31
  • 7
  • Which protocol is your Android using? https://www.howtogeek.com/192732/android-usb-connections-explained-mtp-ptp-and-usb-mass-storage/ – Jim W Mar 23 '18 at 01:02
  • My cellphone devices use MTP – Media Device – posh Mar 23 '18 at 15:40
  • Possible duplicate of [How to manage files on an MTP Portable Device?](https://stackoverflow.com/questions/18512737/how-to-manage-files-on-an-mtp-portable-device) – Jim W Mar 23 '18 at 16:43
  • I've flagged this as a duplicate question, because there's another question with an answer that points to https://cgeers.wordpress.com/2011/08/13/wpd-transferring-content/ basically you're going to have to treat an MTP device completely differently to the regular file system. It's possible and that link will give you what you need. The other question is https://stackoverflow.com/questions/18512737/how-to-manage-files-on-an-mtp-portable-device – Jim W Mar 23 '18 at 16:44

1 Answers1

0

If you just put SAMSUNG\Phone it is treated as a relative path (relative to the current working directory for your application). If you meant to access a UNC share, use \\SAMSUNG\Phone.

John Wu
  • 50,556
  • 8
  • 44
  • 80
  • This still give me an error and I checked with Directory.Exists( returns not found). I also try @"This computer\SAMSUNG\Phone" and that doesn't work. I have the same error. – posh Mar 22 '18 at 22:41
  • 1
    Can you attach a screenshot of the Explorer view that shows the device is there in your filesystem? – John Wu Mar 22 '18 at 22:48
  • i added screenshot on my question above. thank you in advance. – posh Mar 23 '18 at 15:43