Obtain Logical Drive > Better Way?, your call!
- Posted by euman at bellsouth.net Nov 07, 2001
- 421 views
Hello, I found myself looking at our old method to find drives on a machine and thought there must be a better way to do this than 26 for loops so, I did find a way to do it. I thought I would share this interesting little piece with you all. Obtain Logical Drive Letters "strings" w/or w/o ANSI-ASCII - Unicode *should work in both* integer xGetLogicalDriveStrings xGetLogicalDriveStrings = link_c_func( kernel32, "GetLogicalDriveStringsA",{C_LONG,C_POINTER},C_INT) function stripz(object test, sequence data) integer ix, jx, len sequence result result = {} ix = 1 len = length(data) jx = find( test, data[ix..len] ) while jx do result &= {data[ix..ix+jx-2]} ix += jx jx = find( test, data[ix..len]) if ix < len and data[ix] = 0 then ix += 1 jx = find( test, data[ix..len]) end if end while return result end function sequence drives function getdrives() atom DLen_Buf integer DLen DLen_Buf = allocate(256) mem_set( DLen_Buf, 0, 256 ) DLen = c_func(xGetLogicalDriveStrings,{256,DLen_Buf}) if DLen > 256 then free(DLen_Buf) DLen_Buf = allocate(DLen) mem_set( DLen_Buf, 0, DLen ) DLen = c_func(xGetLogicalDriveStrings,{DLen,DLen_Buf}) end if drives = peek({DLen_Buf,DLen}) free(DLen_Buf) drives = stripz(0, drives) return drives end function drives = getdrives Euman euman at bellsouth.net