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
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
[128]5; @file_comments
6; check if a directory exists and make sure that it ends
7; with the directory separator mark.
[2]8;
[93]9; @categories io
[2]10;
[128]11; @param directoryin {in}{optional} a proposed directory. If neither dirname
[11]12;        input parameter of IODIRECTORY keyword are defined,
13;        the ask the user to choose a directory.
[2]14;
[93]15; @keyword IODIRECTORY a proposed directory
[2]16;
[93]17; @keyword TITLE the title of the window
[2]18;
[118]19; @keyword _EXTRA used to pass your keywords
20;
[97]21; @file_comments all dialog_pickfile keywords (like filter) can be used.
[2]22;
[93]23; @returns the directory name
[2]24;
[128]25; @examples
[11]26;
[128]27; IDL> print, !dir
[11]28;    /usr/local/rsi/idl_6.0
[128]29; IDL> print, isadirectory(!dir)
[11]30;    /usr/local/rsi/idl_6.0/
[128]31; IDL> print, isadirectory(!dir+'notgood')
[11]32;
[93]33; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]34;                      June 28, 2000
[11]35; June 2005: Sebastien Masson: cleaning, use for file_* functions
[118]36;
37; @version $Id$
[2]38;-
39;------------------------------------------------------------
40;------------------------------------------------------------
41;------------------------------------------------------------
[11]42FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _extra = ex
[2]43;
[114]44;
45  compile_opt idl2, strictarrsubs
46;
[11]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.