Search code examples
c#pathusbdrive

How to get the path for a usb flash drive


I made this code where it copies a file on my computer to the USB attached to the before mention computer. Here is my code:

            FileInfo file = new FileInfo(all_path);

            file.CopyTo(@"E:\tst\test\testing");

When I try using this on a another computer, it does not work because on that computer the USB is a f:\ drive and on my computer it is a E:\ drive. So how do I make it that the code works on every computer. I hope someone can help me


Solution

  • If your application is running from the stick get your path like described here:

    get path for my .exe

    other option is to check the name of you device. Use the code described here:

    Path of the USB devices which are connected to the machine?