1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:isadirectory |
---|
6 | ; |
---|
7 | ; PURPOSE:check if a directory is in the !path variable or is the |
---|
8 | ; common. end it by '/' under Unix/Linux, ':' under Mac and '\' under |
---|
9 | ; Windows. |
---|
10 | ; |
---|
11 | ; CATEGORY: io |
---|
12 | ; |
---|
13 | ; CALLING SEQUENCE: directory=isadirectory() |
---|
14 | ; |
---|
15 | ; INPUTS:none |
---|
16 | ; |
---|
17 | ; KEYWORD PARAMETERS: |
---|
18 | ; IODIRECTORY:a proposed directory |
---|
19 | ; TITLE: the title of the widget open if we need to choose a |
---|
20 | ; directory. |
---|
21 | ; /NOPATH:do not check if the directory is in the !path |
---|
22 | ; variable. |
---|
23 | ; |
---|
24 | ; OUTPUTS: de directory name |
---|
25 | ; |
---|
26 | ; COMMON BLOCKS: |
---|
27 | ; |
---|
28 | ; SIDE EFFECTS:while statement until we found a good directory... |
---|
29 | ; |
---|
30 | ; RESTRICTIONS: |
---|
31 | ; |
---|
32 | ; EXAMPLE: |
---|
33 | ; |
---|
34 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
35 | ; June 28, 2000 |
---|
36 | ;- |
---|
37 | ;------------------------------------------------------------ |
---|
38 | ;------------------------------------------------------------ |
---|
39 | ;------------------------------------------------------------ |
---|
40 | FUNCTION isadirectory, IODIRECTORY = iodirectory, NOPATH = nopath, TITLE = title |
---|
41 | |
---|
42 | cd, current = current |
---|
43 | ; if directory is undefine, we get the current directory. |
---|
44 | if keyword_set(iodirectory) THEN directory = iodirectory ELSE directory = current |
---|
45 | ; |
---|
46 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
47 | CASE thisOS of |
---|
48 | 'MAC':BEGIN & sep = ':' & pathsep = ',' & end |
---|
49 | 'WIN':BEGIN & sep = '\' & pathsep = ';' & end |
---|
50 | ELSE: BEGIN & sep = '/' & pathsep = ':' & end |
---|
51 | ENDCASE |
---|
52 | ; si directory ou current ne finit pas par sep on le rajoute |
---|
53 | if rstrpos(current,sep) NE strlen(current)-1 then current = current+sep |
---|
54 | if rstrpos(directory, sep) NE strlen(directory)-1 then directory = directory+sep |
---|
55 | if keyword_set(nopath) then return, directory |
---|
56 | ; does directory is define in the !path variable or is it the current directory? |
---|
57 | possibledirectory = str_sep(!path, pathsep) |
---|
58 | if rstrpos(possibledirectory[0],sep) NE strlen(possibledirectory[0])-1 then $ |
---|
59 | possibledirectory = possibledirectory+sep |
---|
60 | possibledirectory = [current, possibledirectory] |
---|
61 | while (where(possibledirectory EQ directory))[0] EQ -1 do begin |
---|
62 | directory = dialog_pickfile(/directory, title = title) |
---|
63 | if directory EQ '' then return, report('read_data canceled') |
---|
64 | if rstrpos(directory, sep) NE strlen(directory)-1 then directory = directory+sep |
---|
65 | endwhile |
---|
66 | |
---|
67 | return, directory |
---|
68 | end |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | |
---|