2013年6月16日 星期日

Procedure GetAllDrives(List Drive.DriveInfo())


Structure DriveInfo
  DriveLetter$
  Volume$
EndStructure

Global NewList Drive.DriveInfo()
Procedure GetAllDrives(List Drive.DriveInfo())
  Protected memLen, *buffer, numDrives, *ptrChar.CHARACTER, i
  memLen = GetLogicalDriveStrings_(0, 0)
  If memlen
    *buffer = AllocateMemory(memLen * SizeOf(CHARACTER))
    If *buffer
      numDrives = GetLogicalDriveStrings_(memLen,*buffer)>>2
      *ptrChar = *buffer
      For i = 1 To numDrives
        AddElement(Drive())
       
        Drive()\DriveLetter$ = UCase(PeekS(*ptrChar,3))
       
        *ptrChar + SizeOf(CHARACTER)<<2
        Drive()\Volume$ = Space(256)
        If Drive()\DriveLetter$ <> "A:\"
          GetVolumeInformation_(Drive()\DriveLetter$, @Drive()\Volume$,255,0,0,0,0,0)
        Else
          Drive()\Volume$="x"
        EndIf
        If Drive()\Volume$=""
          Drive()\Volume$="?"
        EndIf
      Next
      FreeMemory(*buffer)   
    EndIf
  EndIf
EndProcedure
 GetAllDrives(Drive())
drvstr.s="drv"
ForEach Drive()
    drvstr.s=drvstr+Drive()\DriveLetter$  + ":" + Trim(Drive()\Volume$)+"|"
Next
Debug drvstr+"->"           
ClearList(Drive())





沒有留言:

張貼留言