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

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • 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 io
10;
11; @param DIRECTORYIN {in}{optional}
12; a proposed directory. If neither dirname
13; input parameter of IODIRECTORY keyword are defined,
14; the ask the user to choose a directory.
15;
16; @keyword IODIRECTORY
17; a proposed directory
18;
19; @keyword TITLE
20; the title of the window
21;
22; @keyword _EXTRA
23; used to pass your keywords
24;
25; @file_comments
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 Sebastien Masson (smasson\@lodyc.jussieu.fr)
40;                      June 28, 2000
41; June 2005: Sebastien Masson: cleaning, use for file_* functions
42;
43; @version $Id$
44;-
45;------------------------------------------------------------
46;------------------------------------------------------------
47;------------------------------------------------------------
48FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _extra = ex
49;
50;
51  compile_opt idl2, strictarrsubs
52;
53  CASE 1 OF
54    (size(directoryin, /type))[0] EQ 7:directory = directoryin
55    keyword_set(iodirectory):directory = iodirectory
56    ELSE:directory = 'directory that is not existing'
57  ENDCASE
58  testfile = file_test(directory, /directory)
59; if directory doesn't exist, we ask the user to provide a directory name
60  IF total(testfile) NE n_elements(directory) THEN BEGIN
61    IF NOT keyword_set(title) THEN title = 'choose a directory'
62    FOR i = 0, n_elements(directory)-1 DO BEGIN
63      IF testfile[i] EQ 0 THEN BEGIN
64        directory[i] = dialog_pickfile(/directory, title = title $
65                                       , /must_exist, _extra = ex)
66        if directory[i] EQ '' THEN RETURN, report('check/find directory canceled')
67      ENDIF
68    ENDFOR
69  ENDIF
70;
71  directory = file_search(directory, /mark_directory)
72  IF n_elements(directory) EQ 1 THEN RETURN, directory[0] $
73  ELSE RETURN, directory
74;
75END
Note: See TracBrowser for help on using the repository browser.