Author Topic: How can I find the usb drive letter c#  (Read 811 times)

0 Members and 1 Guest are viewing this topic.

k005

  • Mosquito
  • Posts: 3
How can I find the usb drive letter c#
« on: November 19, 2021, 02:19:43 PM »
Hello guys;

There is an xxx.exe file on the drive. How can I find the drive letter on which drive this file is located? can you help?

Thanks.

n.yuan

  • Bull Frog
  • Posts: 333
Re: How can I find the usb drive letter c#
« Reply #1 on: November 20, 2021, 09:34:34 AM »
Obviously, you need search all the drives of the file system of your computer, if you do not know which drive the file would be, regardless it being USB (removable) drive or not.

You can use the static method of System.IO.DriveInfo.GetDrives() to get a list of all available drives, and search each of them until you find the file. With DriveInfo class, you can tell what type of the drive is (fixed. removable, network...).

k005

  • Mosquito
  • Posts: 3
Re: How can I find the usb drive letter c#
« Reply #2 on: November 21, 2021, 07:30:20 AM »
Hi.,


I know which drive the file is on.

on a flash disk.

My goal is to do some sort of license protection. That's why I asked.

let's say ; There is abcd.exe file in G: drive.

What should be the code that gives me the drive letter of this? so how can i get G?