Drive Letter of Digital Camera


How can I get the drive letter of USB drive of my Digital camera?

When the camera drive is activated I get the usual windows menu dialog for the drive. Same as the dialog when you insert a CD (Print Pictures, View SlideShow, Take no Action etc.) . My second question is,  how can I programatically insert a menu for my own application in the dialog?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perthgAuthor Commented:
For the second question, I should have specifically asked, how to create AutoPlay Event Handlers in windows XP with Delphi.

First, since this is a USB device, you will need a USB routine to check for devices plugged in and removed. That can be found at:

Next, you will want to gather up all your existing removable drives when your application starts. Then when you plug in your camera or a USB memory stick, you will be able to get the drive letter.

I do it this way in  TAppName.create

 for Drive := 'a' to 'z' do
  if GetDriveType(PChar(Drive+':\')) = DRIVE_REMOVABLE then

I will set a timer as well toe nsure that everything is loaded up before I go and check what removable drives my system has.

Next, when a USB device is inserted, I start a thread using a thread component like abfThreadComponent and do thesame thing... same check, but I do it twice to ensure that it the drive, gets initialized. I do it like:

procedure deviceinserted(sender: tobject);  // procedure in the USB unit

//My thread execute routine:
 for X := 1 to 2 do
 for Drive := 'd' to 'z' do
    if GetDriveType(PChar(Drive+':\')) = DRIVE_REMOVABLE then
     if not DriveInList(Drive) then
      USBDrive := Drive;

Of course I make a drive list and keep track and search there for my drives and check DriveInList to ensure that what was pluged in is not in the list and is therefoe my newest removable drive. Drive = my USB stick.

DriveInList is:

function DriveInList(Drive:Char) : Boolean;
 X : Integer;
 result := False;
 // Check to see if drive already exists.
 For X := 0 to DriveList.Count -1 do
   if DriveList.Strings[x] = Drive then
    result := true;

The second part of your question should really be asked in a seperate thread since that is a seperate topic. And, where do you want this menu item? In explorer? If you want USB autoplay, that will be a search of some program or file on the memory stick/camera and if found, run it.

I hope this made sense to you and helps.

perthgAuthor Commented:
Thanks John,

but how can I make sure that the USB device is a digital camera and not a flash drive?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

The only way to know for sure is that all digital cameras that are capable of showing up as a removable drive will have a directory in the root called


under this directory will be another directory that is an abrevation of the camera make such as

1002OLYM for an Olympus camera. Under this directory will be your pictures in some form of date-PicNum.jpg

With a FindFile routine or component, (search Torry or DelphiPages for FindFile for D5, works well from D5 to D7), find the DCIM directory.

I do it like:

procedure CheckDCIM;
 StatusBar1.Panels[1].Text := '';
 if DirectoryExists(USBDrive + ':\DCIM') then
   PictureList := TStringList.Create;
   FindFile1.Path := USBDrive + ':\DCIM\';
   FindFile1.FileMask := '*.jpg';
   FindFile1.FileMask := '*.jpeg';
   FindFile1.FileMask := '*.tif';
   FindFile1.FileMask := '*.tiff';
  if PictureList.Count > 0 then
     Screen.Cursor := crHourGlass;
     PictureDirectory := ExtractFileDir(PictureList.Strings[PictureList.Count - 1]);
     ImageViewer.Directory := PictureDirectory;
       StatusBar1.Panels[1].Text := 'No pictures were found in camera!';
       StatusBar1.Panels[0].Text := ' Pictures in Camera: 0'
   Screen.Cursor := crDefault;

By the way, Delay is a dealy routine I like so things appear nicer to the end user. SOmetimes "things" can go too quickly!


procedure Delay(MSecs: Cardinal);
 FirstTick, CurrentTick : Cardinal;
 Done : Boolean;
 Done := FALSE;
 FirstTick := GetTickCount;
 While Not Done do
   CurrentTick := GetTickCount;
   If Int64(CurrentTick) - Int64(FirstTick) < 0 Then
     If CurrentTick >= (Int64(FirstTick) - High(Cardinal) + MSecs) Then
      Done := TRUE;
         If CurrentTick - FirstTick >= MSecs Then
          Done := TRUE;

This should get you started very well!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Did this not help you?

Let me know or please accept.
perthgAuthor Commented:
Thanks, John
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.