From: "Damian Yerrick" Newsgroups: comp.os.msdos.djgpp Subject: How to detect drives attached to a system Date: Sun, 3 Oct 1999 23:04:12 -0500 Organization: Rose-Hulman Institute of Technology Lines: 55 Message-ID: <7t993c$d8a$1@solomon.cs.rose-hulman.edu> NNTP-Posting-Host: yerricde.laptop.rose-hulman.edu X-Trace: solomon.cs.rose-hulman.edu 939009964 13578 137.112.205.146 (4 Oct 1999 04:06:04 GMT) X-Complaints-To: news AT cs DOT rose-hulman DOT edu NNTP-Posting-Date: 4 Oct 1999 04:06:04 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-Mimeole: Produced By Microsoft MimeOLE V5.00.2314.1300 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com IIRC, findfirst() and findnext() do not allow you to detect what drive letters are valid and what drive letters are not valid. This code, however, does. /**************************************\ * DRIVES.C * * Determine available drives * * For DJGPP * * Copr. 1999 Damian Yerrick * \**************************************/ #include #include #include #include int main(void) { unsigned nDrives, curDrive, checkDrive; /* To determine the maximum number of drives available on this system */ _dos_getdrive(&curDrive); printf("Current drive is %c:\n", curDrive + '@'); _dos_setdrive(curDrive, &nDrives); puts("Drive letters installed:"); for(checkDrive = 1; checkDrive <= nDrives; checkDrive++) { unsigned int pdrive; /* in Borland, I used a command similar to if(_chdrive(checkDrive) == 0) */ _dos_setdrive(checkDrive, &pdrive); _dos_getdrive(&pdrive); if(pdrive == checkDrive) printf("%c:, ", checkDrive + '@'); } putchar('\n'); _dos_setdrive(curDrive, &nDrives); return 0; } Can anyone see a problem with this code? It works on Sindows 98's DOS box, but will it have problems under NT? Is there a more portable way to detect all drives on a system? -- Damian Yerrick CM 398, Rose-Hulman Institute of Technology 5500 Wabash Ave Terre Haute, IN 47803 http://come.to/yerrick