[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME:find |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE:similaire a la commance unix find. On donne un nom de |
---|
| 8 | ; fichier et en retour la fonction renvoie le nom du fichier entier |
---|
| 9 | ; (avec tous les repertoires) si le fichier existe dans un des |
---|
| 10 | ; repertoires definit par !path. Dans le cas contraire la function |
---|
| 11 | ; renvoie 'NOT FOUND' |
---|
| 12 | ; |
---|
| 13 | ; CATEGORY:trouver un fichier |
---|
| 14 | ; |
---|
| 15 | ; CALLING SEQUENCE: nom_entier=find('nom_fichier') |
---|
| 16 | ; |
---|
| 17 | ; INPUTS: |
---|
| 18 | ; nom_fichier: un string contenant le nom du fichier. Si ce |
---|
| 19 | ; fichier ne contient pas une extension (.bidule) on essaie de |
---|
| 20 | ; chercher un fichier nom_fichier.pro. Ce string peut contenir le |
---|
| 21 | ; caractere * qui, comme sous unix, remplace n''importe quelle chaine |
---|
| 22 | ; de charactere. |
---|
| 23 | ; |
---|
| 24 | ; KEYWORD PARAMETERS: |
---|
| 25 | ; REPERTOIRE: activer ce mot cle si on veut que find donne |
---|
| 26 | ; uniquement les differents repertoires ou on peut trouver le |
---|
| 27 | ; fichier |
---|
| 28 | ; |
---|
| 29 | ; NOPRO: activer si on ne veut pas que nom_fichier soit complete |
---|
| 30 | ; automatiquement par .pro si il ne contient pas d''extension |
---|
| 31 | ; |
---|
| 32 | ; OUTPUTS: |
---|
| 33 | ; nom_entier: un string ou un vecteur de string. il contient le |
---|
| 34 | ; nom entier du fichier avec tout le chemin depuis le debut de |
---|
| 35 | ; l''arborescence. Si plusieurs fichiers sont trouves (dans |
---|
| 36 | ; differents repertoires ou lors de l''utilisation de *) |
---|
| 37 | ; nom_entier est un vecteur dont chacun de ses elements est une |
---|
| 38 | ; solution possible. Si Le fichier n''est pas trouve nom_entier |
---|
| 39 | ; est egale a 'NOT FOUND'. |
---|
| 40 | ; |
---|
| 41 | ; COMMON BLOCKS: none |
---|
| 42 | ; |
---|
| 43 | ; SIDE EFFECTS: |
---|
| 44 | ; |
---|
| 45 | ; RESTRICTIONS: |
---|
| 46 | ; |
---|
| 47 | ; EXAMPLE: |
---|
| 48 | ; |
---|
| 49 | ; IDL> print, find('*loadct') |
---|
| 50 | ; /local/idl/lib/loadct.pro /local/idl/lib/xloadct.pro |
---|
| 51 | ; IDL> print, find('toto') |
---|
| 52 | ; NOT FOUND |
---|
| 53 | ; IDL> print, find('find') |
---|
| 54 | ; /home/1997001/smasso01/IDL_RD/find.pro |
---|
| 55 | ; IDL> print, find('l*',/rep) |
---|
| 56 | ; /home/1997001/smasso01/IDL_RD/ /local/idl/lib/ /local/idl/lib/obsolete/ |
---|
| 57 | ; |
---|
| 58 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 59 | ; 28/4/1999 |
---|
| 60 | ; 6/7/1999: compatibilite mac et windows |
---|
| 61 | ;- |
---|
| 62 | ;------------------------------------------------------------ |
---|
| 63 | ;------------------------------------------------------------ |
---|
| 64 | ;------------------------------------------------------------ |
---|
| 65 | FUNCTION find, nomfichier, REPERTOIRE = repertoire, NOPRO = nopro |
---|
| 66 | nomfich = nomfichier |
---|
| 67 | ; il faut completer le nom par .pro??? |
---|
| 68 | if NOT keyword_set(nopro) THEN $ |
---|
| 69 | if strpos(nomfich,'.') EQ -1 then nomfich=nomfich+".pro" |
---|
| 70 | ; on cree tous les noms entiers possibles avec les repertoires |
---|
| 71 | ; contenus dans !path |
---|
| 72 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
| 73 | CASE thisOS of |
---|
| 74 | 'MAC':BEGIN & sep = ':' & pathsep = ',' & end |
---|
| 75 | 'WIN':BEGIN & sep = '\' & pathsep = ';' & end |
---|
| 76 | ELSE: BEGIN & sep = '/' & pathsep = ':' & end |
---|
| 77 | ENDCASE |
---|
| 78 | cd, current = current |
---|
| 79 | if strpos(nomfich,sep) lt 0 then BEGIN |
---|
| 80 | if rstrpos(current,sep) NE strlen(current)-1 then current = current+sep |
---|
| 81 | multipath = str_sep(!path,pathsep) |
---|
| 82 | if rstrpos(multipath[0],sep) NE strlen(multipath[0])-1 then multipath = multipath +sep |
---|
| 83 | nomfich = [current, multipath]+ nomfich |
---|
| 84 | ENDIF |
---|
| 85 | ; on test tous les noms possibles pour trouver ou est le fichier |
---|
| 86 | res = [' '] |
---|
| 87 | for n = 0, n_elements(nomfich)-1 do BEGIN |
---|
| 88 | tmp = findfile(nomfich[n]) |
---|
| 89 | if tmp[0] NE '' then res = [res, tmp] |
---|
| 90 | ENDFOR |
---|
| 91 | if n_elements(res) EQ 1 then return, 'NOT FOUND' ELSE BEGIN |
---|
| 92 | res = res[1:n_elements(res)-1] |
---|
| 93 | IF keyword_set(repertoire) then BEGIN |
---|
| 94 | ; on extrait le nom des repertoires |
---|
| 95 | for i = 0,n_elements(res)-1 do res[i] = strmid(res[i], 0, rstrpos(res[i],sep)+1) |
---|
| 96 | ; on supprime les repertoires en double |
---|
| 97 | res = res[uniq(res, sort(res))] |
---|
| 98 | ENDIF |
---|
| 99 | return, res |
---|
| 100 | ENDELSE |
---|
| 101 | end |
---|