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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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