Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hi
I decided to share part of my code
This allows you to find a specific disk based on the label on your computer regardless of what letter it was placed on the system and return its letter.
More info here.
Code:// Drive types:
// "CDRom" = The drive is an optical disc device, such as a CD or DVD-ROM
// "Fixed" = The drive is a fixed disk
// "Network" = The drive is a network drive
// "NoRootDirectory" = The drive does not have a root directory
// "Ram" = The drive is a RAM disk
// "Removable" = The drive is a removable storage device, such as a USB flash drive
// "Unknown" = The type of drive is unknown
var driverLetter = null;
var volumeLabel = null;
var labelName = "PATRIOT"; // name of drive you looking for
var drives = clr.System.IO.DriveInfo.GetDrives();
for (i = 0; i < drives.Length; i++) {
var driveType = drives[i].DriveType.ToString();
if (drives[i].IsReady) { // if the drive is not ready, "drives[i].VolumeLabel" will cause an error
if (driveType == "Removable") { // pendrive
var volumeLabel = drives[i].VolumeLabel;
if (volumeLabel.includes(labelName)) {
driverLetter = drives[i].Name;
break;
}
}
}
}
if (driverLetter) {
sp.MessageBox("Drive letter: " + driverLetter + "\nLabel : " + volumeLabel, "Drive found");
} else {
sp.MessageBox("Drive not found.", "Drive not found");
}
|
1 user thanked Yuichi for this useful post.
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close