1. RE: Blocking Error Msg with GetDrives
- Posted by Al Getz <Xaxo at aol.com> Apr 20, 2001
- 390 views
CK Lester wrote: > Howdy! > > Al! One, final question, regarding the GetDrives code... > > If one of the removable drives (for instance, a floppy drive or an ORB > drive) has no disk in it, I want the program to disregard that > particular > drive. Is there a way to suppress the error and continue without > interruption? > > Thanks! > ck > > > Hi there again ck, I wish some of what you said in your previous post was true, i wouldnt have to work so hard getting some of my code to work As far as the getdrives goes, the info[] for the drive shows whether the drive is ready or not, or you could just look at the sequence "DrivesReady[]" in the following program: --GetDrivesInfo() for older Windows95 versions: include dll.e include msgbox.e global atom hKernel32_dll,hGetLogicalDrives,hGetDiskFreeSpace atom retv hKernel32_dll=open_dll("kernel32.dll") if hKernel32_dll=0 then retv=message_box( "could not locate Kernel32.dll", "GetDrives.exw",MB_ICONHAND+MB_TASKMODAL ) abort(1) end if hGetLogicalDrives= define_c_func(hKernel32_dll, "GetLogicalDrives", {}, C_ULONG) if hGetLogicalDrives<0 then retv=message_box( "could not link to c function"DA& "GetLogicalDrives in Kernel32.dll", "GetDrives.exw",MB_ICONHAND+MB_TASKMODAL) abort(1) end if hGetDiskFreeSpace= define_c_func(hKernel32_dll, "GetDiskFreeSpaceA", {C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_POINTER}, C_ULONG) if hGetDiskFreeSpace<0 then retv=message_box( "could not link to c function"DA& "GetDiskFreeSpace in Kernel32.dll","GetDrives.exw", MB_ICONHAND+MB_TASKMODAL) abort(1) end if function GetDiskFreeSpace(sequence drive) atom lpPathName,lpSectorsPerCluster,lpBytesPerSector, lpNumberOfFreeClusters,lpTotalNumberOfClusters,bool sequence info lpPathName=allocate_string(drive) lpSectorsPerCluster=allocate(4) lpBytesPerSector=allocate(4) lpNumberOfFreeClusters=allocate(4) lpTotalNumberOfClusters=allocate(4) bool=c_func(hGetDiskFreeSpace, {lpPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters}) if bool then info={ bool, peek4u(lpSectorsPerCluster), peek4u(lpBytesPerSector), peek4u(lpNumberOfFreeClusters), peek4u(lpTotalNumberOfClusters) } else info={bool, 0, 0, 0, 0 } end if --warning: --this function shows bytes up to 2gig drive limit, --but thats good enough for most aps needing to know --if there is free space available. --If you have the newer win95+ use GetDrivesInfo(). free(lpPathName) free(lpSectorsPerCluster) free(lpBytesPerSector) free(lpNumberOfFreeClusters) free(lpTotalNumberOfClusters) return info end function retv=c_func(hGetLogicalDrives,{}) sequence message,windows_crlf,drive,Drives,DrivesReady,info, DrivesInfo windows_crlf=#0DA Drives={} DrivesReady={} DrivesInfo={} atom bit integer DriveLetter message="Drives available and ready:"&windows_crlf bit=1 for k=1 to 26 do if and_bits(bit,retv) then DriveLetter=k+96--change to "DriveLetter=k+64" for caps drive=DriveLetter&":\\" info=GetDiskFreeSpace(drive) DrivesInfo=append(DrivesInfo,{drive}&info) if info[1] then message=message&drive&windows_crlf DrivesReady=append(DrivesReady,drive) -- ^only gets loaded with drives that are actually ready. end if Drives=append(Drives,drive) end if bit=bit*2 end for ?DrivesInfo --sequence of all drives available on the system and info puts(1,"\n") --display all drives in the system to console: printf(1,"\n%s",{"All drives in the system:\n"}) for k=1 to length(Drives) do printf(1,"%s\n",{Drives[k]}) end for --display only the drives ready to console: printf(1,"\n%s",{"Drives Ready:\n"}) for k=1 to length(DrivesReady) do printf(1,"%s\n",{DrivesReady[k]}) end for --display all drives available and ready in message box: retv=message_box( message,"GetDrives.exw",MB_TASKMODAL ) --note: --you can get the drives ready from DrivesReady[] or --from looking at DrivesInfo[n][2] and DrivesInfo[n][1]. --notice "DrivesReady[]" only contains the drives with a disk in -- and ready for use. --Good luck with it. --Al