How to get current drive?

Previous topic - Next topic

Szantai

Please be a simple version.
Thanks!
:)

Ruidesco

I understand you mean the drive in Windows where the executable file resides, so:

LCASE$(LEFT$(GETCURRENTDIR$(), 2))

That will return a string like "C:"

Szantai

How is it possible to query the number of drives?

matchy

#3
Code (glbasic) Select

// --------------------------------- //
// Project: getwinvolumes and current volume of currentdir
// Start: Sunday, February 19, 2012
// IDE Version: 10.244

list_volumes()

FUNCTION list_volumes:
LOCAL drive_list$[]

DIM drive_list$[0]

LOCAL timer_temp = GETTIMERALL()
get_win_volumes_active$(drive_list$[])
DEBUG (GETTIMERALL() - timer_temp) + " Active Method\n"

list_drives_passive()
DIM drive_list$[0]

timer_temp = GETTIMERALL()
get_win_volumes_passive$(drive_list$[])
DEBUG (GETTIMERALL() - timer_temp) + " Passsive Method\n"

list_drives_passive()
ENDFUNCTION

FUNCTION list_drives_passive:
LOCAL drive_list$[], drive_id, drive_count, cd$

cd$ = GETCURRENTDIR$()
drive_count = get_win_volumes_passive$(drive_list$[])
FOR drive_id = 1 TO drive_count - 1
DEBUG "Volume " + drive_id + ": " + drive_list$[drive_id] //+ " " + cd$
IF LEFT$(UCASE$(cd$), 2) = LEFT$(UCASE$(drive_list$[drive_id]), 2)
DEBUG " is the current drive."
ENDIF
DEBUG "\n"
NEXT
ENDFUNCTION

FUNCTION get_win_volumes_active$: drive_list$[]
LOCAL chr_id, drive_name$, ok, drive_count

FOR chr_id = 65 TO 65 + 25
drive_name$ = CHR$(chr_id) + ":"
ok = DOESDIREXIST(drive_name$)
IF ok
drive_count = BOUNDS(drive_list$[], 0)
REDIM drive_list$[drive_count + 1]
drive_list$[drive_count] = drive_name$
INC drive_count
ENDIF
NEXT
ENDFUNCTION

FUNCTION get_win_volumes_passive$: drive_list$[]
LOCAL rv, line_data$

LOCAL ok = SHELLCMD("CMD /C fsutil fsinfo drives > volumes.txt", TRUE, FALSE, rv)
GETFILE "volumes.txt", 1, line_data$
RETURN SPLITSTR(line_data$, drive_list$[], " ")
ENDFUNCTION


Kitty Hello

another way is to try C: to Z: with SETCURRENTDIR and check the return value. (untested)

matchy

#5
Actually it's DOESDIREXIST("D:") that does the trick much faster. I've update the code example to and compared both methods as active and passive. The actually question was regarding returning the current drive, which is done by comparing the currentdir drive to the found drives. IF LEFT$(UCASE$(GETCURRENTDIR$()), 2) = LEFT$(UCASE$(drive_list$[drive_id]), 2)