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

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

improvements/corrections of some *.pro headers

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