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

Last change on this file since 128 was 128, checked in by pinsard, 18 years ago

improvements of Utilities/*.pro header

  • 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} 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 a proposed directory
16;
17; @keyword TITLE the title of the window
18;
19; @keyword _EXTRA used to pass your keywords
20;
21; @file_comments all dialog_pickfile keywords (like filter) can be used.
22;
23; @returns the directory name
24;
25; @examples
26;
27; IDL> print, !dir
28;    /usr/local/rsi/idl_6.0
29; IDL> print, isadirectory(!dir)
30;    /usr/local/rsi/idl_6.0/
31; IDL> print, isadirectory(!dir+'notgood')
32;
33; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
34;                      June 28, 2000
35; June 2005: Sebastien Masson: cleaning, use for file_* functions
36;
37; @version $Id$
38;-
39;------------------------------------------------------------
40;------------------------------------------------------------
41;------------------------------------------------------------
42FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _extra = ex
43;
44;
45  compile_opt idl2, strictarrsubs
46;
47  CASE 1 OF
48    (size(directoryin, /type))[0] EQ 7:directory = directoryin
49    keyword_set(iodirectory):directory = iodirectory
50    ELSE:directory = 'directory that is not existing'
51  ENDCASE
52  testfile = file_test(directory, /directory)
53; if directory doesn't exist, we ask the user to provide a directory name
54  IF total(testfile) NE n_elements(directory) THEN BEGIN
55    IF NOT keyword_set(title) THEN title = 'choose a directory'
56    FOR i = 0, n_elements(directory)-1 DO BEGIN
57      IF testfile[i] EQ 0 THEN BEGIN
58        directory[i] = dialog_pickfile(/directory, title = title $
59                                       , /must_exist, _extra = ex)
60        if directory[i] EQ '' THEN RETURN, report('check/find directory canceled')
61      ENDIF
62    ENDFOR
63  ENDIF
64;
65  directory = file_search(directory, /mark_directory)
66  IF n_elements(directory) EQ 1 THEN RETURN, directory[0] $
67  ELSE RETURN, directory
68;
69END
Note: See TracBrowser for help on using the repository browser.