comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » find_subtree.pro
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
find_subtree.pro [message #11907] Tue, 02 June 1998 00:00 Go to next message
Kristian Kjaer is currently offline  Kristian Kjaer
Messages: 58
Registered: June 1998
Member
Hi,

I am looking for piece of code - similar to findfile() - which will
return the fully-qualified paths to all subdirectories of the default
directory, or return the fully-qualified paths to, say, all files *.dat
in all subdirectories of the default directory.

(I use IDL 5 on WinNT.)

Any hints appreciated!

-------------------- Msg. from: ---------------------------
Kristian Kjaer 'phone +45 4677 4709 (dir. line)
Physics Department, Fax +45 4677 4790
Risoe National Laboratory, 'phone +45 4677 4677 (sw.-board)
DK-4000 Roskilde,
Denmark e-mail: Kristian.Kjaer@Risoe.DK
Re: find_subtree.pro [message #11972 is a reply to message #11907] Fri, 05 June 1998 00:00 Go to previous messageGo to next message
R. Bauer is currently offline  R. Bauer
Messages: 137
Registered: November 1996
Senior Member
Kristian Kjaer wrote:

> Hi,
>
> I am looking for piece of code - similar to findfile() - which will
> return the fully-qualified paths to all subdirectories of the default
> directory, or return the fully-qualified paths to, say, all files *.dat
> in all subdirectories of the default directory.
>
> (I use IDL 5 on WinNT.)
>
> Any hints appreciated!
>
> -------------------- Msg. from: ---------------------------
> Kristian Kjaer 'phone +45 4677 4709 (dir. line)
> Physics Department, Fax +45 4677 4790
> Risoe National Laboratory, 'phone +45 4677 4677 (sw.-board)
> DK-4000 Roskilde,
> Denmark e-mail: Kristian.Kjaer@Risoe.DK

Dear Kristian

here is some piece of code, which you can extend yourself.
You need in addition stress and strep from the Ray Sterner lib.


;
; Copyright (c) 1997, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
;
; This software may be used, copied, or redistributed as long as it
is not
; sold and this copyright notice is reproduced on each copy made.
This
; routine is provided as is without any express or implied
warranties
; whatsoever.
;+
; NAME:
; get_dir
;
; PURPOSE:
; This function finds all subdirectories of a given path
;
; CATEGORY:
; DATAFILES/FILE
;
; CALLING SEQUENCE:
; Result=get_dir(path)
;
; INPUTS:
; path: The start path where get_dir should look for subdirectories
;
;
; KEYWORD PARAMETERS:
; all: in addition to the normal subdirectories the entries . and
..
; sort: sorts the output
; help: gaves a short description
;
; OUTPUTS:
; The result of this function is a string array of subdirectories
;
;
; EXAMPLE:
; Result=get_dir('/usr/local')
; or
; Result=get_dir('\windows')
;
; MODIFICATION HISTORY:
; Written by: R.Bauer (ICG-1), May 1997
;-

function get_dir,help=help,inpath,sort=sort,all=all
;debug,'1.1 RB 1997-Dec-22'

if keyword_set(help) then begin
print,"print,get_dir('/')"
print,'===================================================== ===='
return,''
endif

if n_elements(inpath) gt 0 then begin
cd,current=oldpath ; alten path saven
cd,inpath
endif

if strupcase(!version.os) eq 'WIN32' or strupcase(!version.os) eq 'WIN'
then delim = '*.*' ELSE delim='-Fd *'
alle_ein=findfile(delim)

if n_elements(inpath) gt 0 then cd,oldpath ; alten path restoren
if strupcase(!version.os) eq 'AIX' THEN delim = '/' ELSE delim = '\'
if strupcase(!version.os) eq 'AIX' then alle_ein =
['./','../',alle_ein]

subs=where(strpos(alle_ein,delim) ge 0,count)

if count gt 0 then begin
nur_subdirs=alle_ein(subs)

n_Anz=n_elements(nur_subdirs)-1

for i=0,n_anz do begin
nur_subdirs(i)=stress(nur_subdirs(i),'D',0,delim)
endfor

if keyword_set(sort) then $
nur_subdirs=nur_subdirs(sort(nur_subdirs))

if keyword_set(all) then return, nur_subdirs

if n_anz ge 2 then nur_subdirs=nur_subdirs(2:n_anz) else
nur_subdirs=''

return,nur_subdirs
endif


if count eq -1 then return,''


END


===== CUT HERE ======


FUNCTION files_in_dirs ,dir=dir,pattern=pattern

IF n_elements(dir) EQ 0 THEN dir = '.'
IF n_elements(pattern) EQ 0 THEN pattern = '*.*'
dirs = get_dir(dir)

n_dirs = n_elements(dirs)
FOR i=0,n_dirs-1 DO BEGIN
files = findfile(dir+dirs(i)+'/'+pattern)
IF n_elements(result) EQ 0 THEN result = files ELSE result =
[result,files]
ENDFOR

return,result


END

==== CUT HERE ======

PRO ex_subtree

print,files_in_dirs(dir='../',pattern='*.pro')

END







--
R.Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
Re: find_subtree.pro [message #12053 is a reply to message #11907] Fri, 12 June 1998 00:00 Go to previous message
Robert Moss is currently offline  Robert Moss
Messages: 74
Registered: February 1996
Member
R. Bauer wrote:
>
> You need in addition stress and strep from the Ray Sterner lib.
>

Man, I have enough stress in my life already...

sorry, couldn't resist that one...

--
Robert M. Moss, Ph.D. - mossrm@texaco.com - FAX (713)954-6911
------------------------------------------------------------ -----
This does not necessarily reflect the opinions of Texaco Inc.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Normally distributed vectors
Next Topic: ENVI?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:13:21 PDT 2025

Total time taken to generate the page: 0.00687 seconds