Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get drive letter/volume label from all connected drives

Posted on 2008-06-20
2
Medium Priority
?
10,298 Views
Last Modified: 2012-06-22
Gents,

I already use the following function to get the volume label using a specific drive letter. I need to be able to scan each connected drive and call this function for each drive. (Unless there is a better way)

Project description:

I am building a video player that works with a database. When I want to play a file, I look in the database to know on which drive the video is stored.

Each drive has got a specific volume label such as BB1, BB2, BB3, ect.

I have built a 4 bay hot swappable HDD USB reader.

Lets say I want to play a file which is stored on BB7.

I need to look through the present HDDs in my reader to see if BB7 is in. If so, play the file, else prompt the user to insert BB7.

In my database, the file name is stored in a string "\Video\myfile.mp2" so I only need to add the right drive letter to the begining of the string in order to pass to my player.

I am not too keen in scanning drive letters from D to Z to look for the label. I would like a cleaner solution, scan through connected drives...

Many thanks.


function GetVolumeLabel(DriveChar: Char): string;
var
  NotUsed:     DWORD;
  VolumeFlags: DWORD;
  VolumeInfo:  array[0..MAX_PATH] of Char;
  VolumeSerialNumber: DWORD;
  Buf: array [0..MAX_PATH] of Char;
begin
    GetVolumeInformation(PChar(DriveChar + ':\'),
    Buf, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
    VolumeFlags, nil, 0);
 
    SetString(Result, Buf, StrLen(Buf));   { Set return result }
    Result:=AnsiUpperCase(Result)
end;

Open in new window

0
Comment
Question by:etiennedemers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
ThievingSix earned 1500 total points
ID: 21832013
I know you didn't ask for scanning through all drives, but it takes less time than GetTickCount to update..
function GetVolumeLabel(DriveChar: Char): string;
var
  NotUsed:     DWORD;
  VolumeFlags: DWORD;
  VolumeInfo:  array[0..MAX_PATH] of Char;
  VolumeSerialNumber: DWORD;
  Buf: array [0..MAX_PATH] of Char;
begin
    GetVolumeInformation(PChar(DriveChar + ':\'),
    Buf, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
    VolumeFlags, nil, 0);
 
    SetString(Result, Buf, StrLen(Buf));   { Set return result }
    Result:=AnsiUpperCase(Result)
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  Drive : Char;
  DriveLetter : String;
begin
  For Drive := 'A' To 'Z' Do
    begin
    DriveLetter := Drive + ':\';
    If GetDriveType(PChar(DriveLetter)) = DRIVE_FIXED Then
      begin
      Memo1.Lines.Add(Drive + ': ' + GetVolumeLabel(Drive));
    end;
  end;
end;

Open in new window

0
 

Author Closing Comment

by:etiennedemers
ID: 31469162
This will achieve my goals.

Many thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question