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

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

add $ in Calendar, Grid, Interpolation, Obsolete and Postscript *.pro files, add svn:keywords Id to all these files, some improvements in header

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