Recursive method call getting terminated ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Recursive method call getting terminated ???
# 1  
Old 10-17-2006
MySQL Recursive method call getting terminated ???

Hello people,

Need help !!! What am I doing wrong here ?

I am writing a function to recursively list the files under a folder and it's sub-folders. Problem is once it list the files under the innermost folder, it terminates. What do I need to do so that it returns and list files under the other folders under the topmost folder. Below please find the method declaration:

############################################
listfiles()
############################################
{
dir=$1

echo "Listing files under folder $dir"
files=`ls -1 $dir`

for file in `echo $files`
do
if [ -d $dir/$file ]; then
#recursive call
listfiles $dir/$file
fi

echo $dir/$file
done
}

Regards,
T.
# 2  
Old 10-17-2006
Is it because the value of the variable "files" is getting overwritten in each recursive call? Do I have to make the variable name dynamic instead of "files" ?

Regards,
T.
# 3  
Old 10-17-2006
wouldn't it be easier to do 'find . -type f' ?

Last edited by vgersh99; 10-18-2006 at 11:47 AM..
# 4  
Old 10-18-2006
Bug

Thanks vgersh99.
I should have posted this query much earlier instead of breaking me head :-)

Regards,
T.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Perl error: Can't call method "value" on an undefined value

Hi, I am running a perl script to automate a process and I keep running into a error can't find the "value" Can't call method "value" on an undefined value at process_file.pl line 44. file is CVS cell is ifdfdxrfmp.ksh Here is the script I have also attached it as well: ... (2 Replies)
Discussion started by: vpundit
2 Replies

2. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

3. HP-UX

oracle session is not terminated on HP-UX

In our HP-UX B.11.11 U 9000/800 PA-RISC 64bits server, the oracle session is not terminated using JDBC after closing the session, we close the java.sql.Statement java.sql.Result and java.sql.Connection on app. In others servers (GNU/Linux debian), the sessions are ending without problems, using... (1 Reply)
Discussion started by: miguecg
1 Replies

4. Shell Programming and Scripting

Search pattern not terminated

Hi, What am i missing on line 16, when I run this I get Search pattern not terminated at count-scr.pl line 16 #!perl open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n"; ##### Step 1, read subnetsopen(my $in, "<names.txt") or die "Could not open names.txt: $!\n";while(<$in>)... (3 Replies)
Discussion started by: richsark
3 Replies

5. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

6. Shell Programming and Scripting

Recursive function call problem

This is shell script I have made to lists out directory contents and filenames for any given directory (without using ls command). There is some problem in dirfunc function call which I have marked 1 is not working. Can anybody suggest what is the problem there and how should I correct it. ... (2 Replies)
Discussion started by: netresearch
2 Replies

7. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

8. UNIX for Dummies Questions & Answers

PID - Getting the processname of terminated/old Process

Hi all! I'm using CentOS 5.2 with KDE. Is it possible to get a processname/cmd of a terminated process (= PID not present with PS-command) ? Are the processnames/scriptnames logged somewhere? (I did not find them in /var/log/messages) (5 Replies)
Discussion started by: JohnMurdoch
5 Replies

9. UNIX for Advanced & Expert Users

command terminated abnormally

I am getting an Error Message as ============================= starting Sortcl Merging And Aggregation time: command terminated abnormally. ============================= , when running a sortcl command.sortcl is a command for sorting large data,using cosort application installed in... (0 Replies)
Discussion started by: tkbharani
0 Replies

10. AIX

Process got terminated automatically

Hi, I am elango. I am working with UNIX AIX version 5. I am facing tow problem whenever I am trying to run a script. 1. The moment I run the script 3 more jobs are getting started automatically. I used PS -ef command to check the running Jobs, I found totally 4 jobs are running for... (4 Replies)
Discussion started by: Elango
4 Replies
Login or Register to Ask a Question