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