---
title: "How to Check presence of a usb drive using C#?"  
description: "How to Check presence of a usb drive using C#?"  
author: "Andrew Deniel"  
published: 2013-10-16  
updated: 2013-10-16  
canonical: https://www.mindstick.com/forum/1694/how-to-check-presence-of-a-usb-drive-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to Check presence of a usb drive using C#?

I am [writing](https://www.mindstick.com/articles/12997/5-essential-tips-on-resume-writing-for-business-analysts) a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) that extracts [xml](https://www.mindstick.com/blog/203/working-with-xml-data-in-sql-server) to obtain [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) of [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) and need to [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) these files to the [USB](https://www.mindstick.com/articles/13074/what-makes-usb-c-cables-better-than-other-usb-cables) drive. The first 2 steps I able to do this.

my [questions](https://www.mindstick.com/blog/124895/hp-hpe0-s54-cheat-sheet-exam-questions-bank-for-guaranteed-success) is:

1. How can I [detect if](https://www.mindstick.com/forum/12896/how-to-detect-if-device-support-eap-sim) there is a USB Drive

2. Then detect which drive it is.

Thanks

## Replies

### Reply by Anonymous User

```
foreach (DriveInfo removableDrive in DriveInfo.GetDrives().Where(
            d => d.DriveType == DriveType.Removable && d.IsReady))
        {
            DirectoryInfo rootDirectory = removableDrive.RootDirectory;
            string monitoredDirectory = Path.Combine(rootDirectory.FullName, DIRECTORY_TO_MONITOR);
            string localDestDirectory = Path.Combine(destDirectory, removableDrive.VolumeLabel);
            if (!Directory.Exists(localDestDirectory))
                Directory.CreateDirectory(localDestDirectory);
            if (Directory.Exists(monitoredDirectory))
            {
                foreach (string file in Directory.GetFiles(monitoredDirectory))
                {
                    File.Copy(file, Path.Combine(localDestDirectory, Path.GetFileName(file)), true);
                }
            }
        }
```


---

Original Source: https://www.mindstick.com/forum/1694/how-to-check-presence-of-a-usb-drive-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
