[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Win32 and Removeable Drives



Hi Bernard,

I think the best way is to catch the error using a wrapper function
heres a couple of functions which I tested on Win 2000.  Hope they do the
job for you.

example usage:

IDL> print, dir_exist("c:")
       1
IDL> print, dir_exist("f:")
       1
; eject media
IDL> print, dir_exist("f:\")
       0
IDL> safe_cd, "f:",  success = success
IDL> print, success
       0

regards

Martin
;---------------------------------------------------------------------------
--
; Wrapper function for CD - change directory
; Martin Downing 2000
; If it catches an error, sucess is set to 0 otherwise 1
pro safe_cd, dir, success=success, current = current, debug=debug

 ; error handling
 Catch, error_status
 IF Error_status NE 0 THEN BEGIN
  if keyword_set(DEBUG) then begin
   PRINT, "Directory change failed"
    PRINT, 'Error message: ', !ERROR_STATE.MSG
  endif
  success = 0
  return
 ENDIF

 ; try to change directory
 cd, dir , cur = current
 ; if we get this far then everything must be ok
 success = 1
 return
end

;---------------------------------------------------------------------------
--
; Test if a directory exists
function dir_exist, dir
 cd, cur = cur
 safe_cd, dir, success=success
 if success eq 1 then cd, cur
 return, success
end

;---------------------------------------------------------------------------
--


--
----------------------------------------
Mr. Martin Downing,
Clinical Research Physicist,
Orthopaedic RSA Research Centre,
Woodend Hospital,
Aberdeen, AB15 6LS.
Tel. 01224 556055
Fax. 01224 556662
m.downing@abdn.ac.uk
"Bernard Puc" <bpuc@va.aetc.com> wrote in message
3A92D8C3.3A6CFC9A@va.aetc.com">news:3A92D8C3.3A6CFC9A@va.aetc.com...
> Hello,
>
> I need some help with determining whether a removable drive has media
> installed or not on a win32 platform running windows.  Specifically, how
> can I do it?  I need to use the CD command but I also need to verify
> that the drive is readable beforehand.  Any clues much appreciated.
>
> -Bernard Puc
> AETC, Inc.