source: trunk/SRC/Utilities/isadirectory.pro @ 224

Last change on this file since 224 was 224, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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