[2] | 1 | ;+ |
---|
[231] | 2 | ; |
---|
[128] | 3 | ; @file_comments |
---|
| 4 | ; check if a directory exists and make sure that it ends |
---|
| 5 | ; with the directory separator mark. |
---|
[2] | 6 | ; |
---|
[224] | 7 | ; @categories |
---|
[325] | 8 | ; Input/Output |
---|
[2] | 9 | ; |
---|
[224] | 10 | ; @param DIRECTORYIN {in}{optional} |
---|
[136] | 11 | ; a proposed directory. If neither dirname |
---|
| 12 | ; input parameter of IODIRECTORY keyword are defined, |
---|
[237] | 13 | ; we ask the user to choose a directory. |
---|
[2] | 14 | ; |
---|
[224] | 15 | ; @keyword IODIRECTORY |
---|
[136] | 16 | ; a proposed directory |
---|
[2] | 17 | ; |
---|
[224] | 18 | ; @keyword TITLE |
---|
[136] | 19 | ; the title of the window |
---|
[2] | 20 | ; |
---|
[224] | 21 | ; @keyword _EXTRA |
---|
[260] | 22 | ; Used to pass keywords to <proidl>DIALOG_PICKFILE</proidl> |
---|
[118] | 23 | ; |
---|
[224] | 24 | ; @returns |
---|
[136] | 25 | ; the directory name |
---|
[2] | 26 | ; |
---|
[128] | 27 | ; @examples |
---|
[11] | 28 | ; |
---|
[371] | 29 | ; IDL> print, !dir |
---|
[11] | 30 | ; /usr/local/rsi/idl_6.0 |
---|
[371] | 31 | ; IDL> print, isadirectory(!dir) |
---|
[11] | 32 | ; /usr/local/rsi/idl_6.0/ |
---|
[371] | 33 | ; IDL> print, isadirectory(!dir+'notgood') |
---|
[11] | 34 | ; |
---|
[224] | 35 | ; @history |
---|
| 36 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 37 | ; June 28, 2000 |
---|
[11] | 38 | ; June 2005: Sebastien Masson: cleaning, use for file_* functions |
---|
[118] | 39 | ; |
---|
[224] | 40 | ; @version |
---|
| 41 | ; $Id$ |
---|
[237] | 42 | ; |
---|
[2] | 43 | ;- |
---|
[327] | 44 | FUNCTION isadirectory, directoryin, TITLE=title, IODIRECTORY=iodirectory $ |
---|
| 45 | , _EXTRA=ex |
---|
[2] | 46 | ; |
---|
[114] | 47 | compile_opt idl2, strictarrsubs |
---|
| 48 | ; |
---|
[11] | 49 | CASE 1 OF |
---|
| 50 | (size(directoryin, /type))[0] EQ 7:directory = directoryin |
---|
| 51 | keyword_set(iodirectory):directory = iodirectory |
---|
| 52 | ELSE:directory = 'directory that is not existing' |
---|
| 53 | ENDCASE |
---|
| 54 | testfile = file_test(directory, /directory) |
---|
| 55 | ; if directory doesn't exist, we ask the user to provide a directory name |
---|
| 56 | IF total(testfile) NE n_elements(directory) THEN BEGIN |
---|
| 57 | IF NOT keyword_set(title) THEN title = 'choose a directory' |
---|
| 58 | FOR i = 0, n_elements(directory)-1 DO BEGIN |
---|
| 59 | IF testfile[i] EQ 0 THEN BEGIN |
---|
| 60 | directory[i] = dialog_pickfile(/directory, title = title $ |
---|
| 61 | , /must_exist, _extra = ex) |
---|
| 62 | if directory[i] EQ '' THEN RETURN, report('check/find directory canceled') |
---|
| 63 | ENDIF |
---|
| 64 | ENDFOR |
---|
| 65 | ENDIF |
---|
| 66 | ; |
---|
[243] | 67 | directory = file_search(directory, /mark_directory, /test_directory, /fully_qualify_path) |
---|
[11] | 68 | IF n_elements(directory) EQ 1 THEN RETURN, directory[0] $ |
---|
| 69 | ELSE RETURN, directory |
---|
| 70 | ; |
---|
| 71 | END |
---|