Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Disk in drive a:\?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00650854
Message ID:
00652069
Views:
23
You can try this:


FUNCTION DriveReady

LPARAMETER disk_name,; && Disk drive
read_write && .T. - to test is the disk is not read only
LOCAL ret_val, m_name, nFiles,nLastError,cError
DECLARE SetErrorMode IN "kernel32.dll" INTEGER test
DECLARE SetLastError IN "kernel32.dll" INTEGER test
DECLARE INTEGER GetLastError IN "Kernel32.dll"
DECLARE INTEGER FormatMessage IN "kernel32.dll" INTEGER flags,;
INTEGER notused,;
INTEGER error,;
INTEGER locale,;
STRING @buffer,;
INTEGER bufsize,;
INTEGER notused
=SetLastError(0)
=SetErrorMode(1)
m_name = disk_name + SUBSTR(SYS(2015), 3, 10)
nFiles = ADIR(temP_name,disk_name+"*.*")
ret_val = 0
IF nFiles=0
nLastError=GetLastError()
DO CASE
CASE nLastError = 19 && The disk is read-only
ret_val = 19
CASE nLastError = 21 && There is no disk in thw drive
ret_val = 21
CASE nLastError # 0 .AND.; && Some other message
nLastError # 2 && Error # 2
cError=SPACE(255)
=FormatMessage(4096,0,nLastError,0,@cError,255,0)
cError=ALLTRIM(STRTRAN(cError,CHR(0)))
WAIT WINDOW 'Error ¹: '+ALLTRIM(STR(nLastError))+CHR(13)+'Ãðåøêà: '+cError
ret_val = 99
ENDCASE
ENDIF
IF read_write
nFiles = FCREATE(m_name)
nLastError=GetLastError()
DO CASE
CASE INLIST(nLastError,0,2)
FCLOSE(nFiles)
ERASE (m_name)
CASE nLastError = 19
ret_val = 19
CASE nLastError = 21
ret_val = 21
CASE nLastError # 0
cError=SPACE(255)
=FormatMessage(4096,0,nLastError,0,@cError,255,0)
cError=ALLTRIM(STRTRAN(cError,CHR(0)))
WAIT WINDOW 'Error ¹: '+ALLTRIM(STR(nLastError))+CHR(13)+'Ãðåøêà: '+cError
ret_val = 99
ENDCASE
ENDIF
=SetErrorMode(1)
=SetLastError(0)

RETURN ret_val
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform