Drive letter

This is a discussion on Drive letter within the C++ Programming forums, part of the General Programming Boards category; How can I obtain the drive letter of my cdrom. I'm trying to write a program that will install multiple ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    5

    Drive letter

    How can I obtain the drive letter of my cdrom. I'm trying to write a program that will install multiple programs. I want to put it all on a cdrom, and if I hard-code the drive letter in it will most likely not work on any other computer if the cdrom drive letter is different. So, I need to know how I can obtain the drive letter. Any ideas.....?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    OS and compiler?
    My best code is written with the delete key.

  3. #3
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    I can't think of an OS besides windows that uses drive letters.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    <direct.h> has a data structure diskfree_t, and a function getdiskfree() that could be used to 'guess' which is the cdrom. The first parameter of getdiskfree() is the drive to check - 0 is the 'normal' drive and can be ignored. 1 is A:, 2 is B:, and so on. So you would set up a loop to call getdiskfree() on each drive, and then multiply total_clusters * avail_clusters * sectors_per_cluster in the diskfree_t structure, and compare that value with the size of a cdrom disk. It's not foolproof, but as far as I know, there really aren't any other options. Why don't you just prompt the user for the drive letter?
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    On windows use GetLogicalDriveStrings() and GetDriveType().

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I can't think of an OS besides windows that uses drive letters.
    DOS uses drive letters, and the Windows solution most certainly won't work with DOS. Just because you can't think of an exception doesn't mean one doesn't exist.
    My best code is written with the delete key.

  7. #7
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Quote Originally Posted by Prelude
    >I can't think of an OS besides windows that uses drive letters.
    DOS uses drive letters, and the Windows solution most certainly won't work with DOS. Just because you can't think of an exception doesn't mean one doesn't exist.
    SuSE Linux uses drive letters. I presume other Linux distros do too.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    5
    Sorry for not including the OS and Compiler, But I am running Windows XP and using Visual Studio.NET. I guess I could prompt them for a Drive, or instead of making an executable I could do it all in a Batch file.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I am running Windows XP and using Visual Studio.NET
    A GetLogicalDriveStrings/GetDriveType combo is pretty much what you want:
    Code:
    #include <cstdio>
    
    using namespace std;
    
    char drives[BUFSIZ];
    char *p;
    
    GetLogicalDriveStrings ( BUFSIZ, drives );
    p = drives;
    printf ( "Your CD-ROM drives are\n" );
    while ( *p != '\0' ) {
      if ( GetDriveType ( p ) == DRIVE_CDROM ) {
        printf ( "%c\n", *p );
      }
      p = strchr ( p, '\0' ) + 1;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help using strings and mapping
    By trprince in forum C Programming
    Replies: 29
    Last Post: 12-01-2007, 03:01 PM
  2. How do I get the Drive Letter?
    By LiX in forum C++ Programming
    Replies: 12
    Last Post: 12-19-2004, 10:48 AM
  3. Choosing drive letter
    By *ClownPimp* in forum Tech Board
    Replies: 4
    Last Post: 07-11-2003, 02:40 PM
  4. probe for drive letter assignment
    By iain in forum C Programming
    Replies: 3
    Last Post: 02-07-2002, 07:49 PM
  5. Drive letter
    By CyberCreationz in forum C Programming
    Replies: 1
    Last Post: 02-07-2002, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21