Changeset 11 for trunk/Utilities/isadirectory.pro
- Timestamp:
- 04/27/06 11:05:35 (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/isadirectory.pro
r9 r11 5 5 ; NAME:isadirectory 6 6 ; 7 ; PURPOSE:check if a directory is in the !path variable or is the 8 ; common. end it by '/' under Unix/Linux, ':' under Mac and '\' under 9 ; Windows. 7 ; PURPOSE:check if a directory exists and make sure that it ends 8 ; with the directory separator mark. 10 9 ; 11 10 ; CATEGORY: io 12 11 ; 13 ; CALLING SEQUENCE: directory=isadirectory( )12 ; CALLING SEQUENCE: directory=isadirectory([dirname]) 14 13 ; 15 ; INPUTS:none 14 ; INPUTS:optional:a proposed directory. If neither dirname 15 ; input parameter of IODIRECTORY keyword are defined, 16 ; the ask the user to choose a directory. 16 17 ; 17 18 ; KEYWORD PARAMETERS: 18 ; IODIRECTORY:a proposed directory19 ; TITLE: the title of the widget open if we need to choose a20 ; directory.21 ; /NOPATH:do not check if the directory is in the !path22 ; variable.23 19 ; 24 ; OUTPUTS: de directory name20 ; IODIRECTORY:a proposed directory 25 21 ; 26 ; COMMON BLOCKS:22 ; TITLE = the title of the window 27 23 ; 28 ; SIDE EFFECTS:while statement until we found a good directory... 24 ; all dialog_pickfile keywords (like filter) 25 ; 26 ; OUTPUTS: the directory name 27 ; 28 ; COMMON BLOCKS:none 29 ; 30 ; SIDE EFFECTS: 29 31 ; 30 32 ; RESTRICTIONS: … … 32 34 ; EXAMPLE: 33 35 ; 36 ; IDL> print, !dir 37 ; /usr/local/rsi/idl_6.0 38 ; IDL> print, isadirectory(!dir) 39 ; /usr/local/rsi/idl_6.0/ 40 ; IDL> print, isadirectory(!dir+'notgood') 41 ; 34 42 ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) 35 43 ; June 28, 2000 44 ; June 2005: Sebastien Masson: cleaning, use for file_* functions 36 45 ;- 37 46 ;------------------------------------------------------------ 38 47 ;------------------------------------------------------------ 39 48 ;------------------------------------------------------------ 40 FUNCTION isadirectory, IODIRECTORY = iodirectory, NOPATH = nopath, TITLE = title 41 42 cd, current = current 43 ; if directory is undefine, we get the current directory. 44 if keyword_set(iodirectory) THEN directory = iodirectory ELSE directory = current 49 FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _extra = ex 45 50 ; 46 thisOS = strupcase(strmid(!version.os_family, 0, 3))47 CASE thisOS of48 'MAC':BEGIN & sep = ':' & pathsep = ',' & end49 'WIN':BEGIN & sep = '\' & pathsep = ';' & end50 ELSE: BEGIN & sep = '/' & pathsep = ':' & end51 ENDCASE52 ; si directory ou current ne finit pas par sep on le rajoute53 if rstrpos(current,sep) NE strlen(current)-1 then current = current+sep54 if rstrpos(directory, sep) NE strlen(directory)-1 then directory = directory+sep55 if keyword_set(nopath) then return, directory56 ; does directory is define in the !path variable or is it the current directory? 57 possibledirectory = str_sep(!path, pathsep)58 if rstrpos(possibledirectory[0],sep) NE strlen(possibledirectory[0])-1 then $59 possibledirectory = possibledirectory+sep60 possibledirectory = [current, possibledirectory]61 while (where(possibledirectory EQ directory))[0] EQ -1 do begin62 directory = dialog_pickfile(/directory, title = title)63 if directory EQ '' then return, report('read_data canceled') 64 if rstrpos(directory, sep) NE strlen(directory)-1 then directory = directory+sep65 endwhile66 67 return, directory 68 end 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 ; 73 END 69 74 70 75
Note: See TracChangeset
for help on using the changeset viewer.