Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!samsung!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!mephisto!prism!bb16 From: bb16@prism.gatech.EDU (Scott Bostater) Newsgroups: comp.lang.pascal Subject: Re: Rusty programmer seeks help... Message-ID: <4222@hydra.gatech.EDU> Date: 8 Dec 89 06:26:22 GMT References: <5651@uhccux.uhcc.hawaii.edu> Reply-To: bb16@prism.gatech.EDU (Scott Bostater) Distribution: usa Organization: Georgia Institute of Technology Lines: 35 In article <5651@uhccux.uhcc.hawaii.edu> webb@uhccux.UUCP (Thomas Webb) writes: [ problem with recursive subroutine stated ] >program treetmp; > >uses DOS; > >var >dirInfo: SearchRec; >nextDirectory:string; > >procedure tree(next:string); >var > dtmp:string; >begin [ guts of procedure deleted to keep rn happy :-( ] >end; [ rest of program deleted ] Your problem is that the variable DirInfor is not local to your recursive routine. What's happening is that the second call over-writes the information in DirInfo that specifies what the filename and pathname are. By making Dirinfo local to the procedure tree, you keep making copies of Dirinfo on the heap so that when you return from one level of recursion, the previous data in the old version of DirInfo is still intact. This method works fine as long as you have plenty of heap/stack space! -- Scott Bostater GTRI/RAIL/RAD (Ga. Tech) "My soul finds rest in God alone; my salvation comes from Him" -Ps 62.1 uucp: ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!bb16 Internet: bb16@prism.gatech.edu