Link to home
Start Free TrialLog in
Avatar of tiger0516
tiger0516

asked on

A recursive call quesion

I am writing a ls-like command in unix and I have some troubles when implementing ls -R call.

Currently, my output is something like

file1
file2
sub-directory1
      file3 in sub-directory1
      file4 in sub-directory1
file5
sub-directory2
      file6 sub-directory2

But ls -R output is:

file1
file2
file5

sub-directory1
      file3 in sub-directory1
      file4 in sub-directory1

sub-directory2
      file6 in sub-directory2

I think I made some mistakes in the recursive call. Any help?

Thanks
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Hi tiger0516,

Without seeing your code, I suspect that you're processing the files/directories in the current directory in the order that you encounter them.

You'll need to "save" the directories in a table as you encounter them and list the files.  Then process the list of directories.

Or save both in a list, process the directories, then process the files.


Good Luck!
Kent
Avatar of tiger0516
tiger0516

ASKER

>Without seeing your code, I suspect that you're processing the files/directories in the current directory in the order that you encounter them.

Yes,  I did so

>You'll need to "save" the directories in a table as you encounter them and list the files.  Then process the list of directories.

Do you mean a table for all directories? But, for example, a sub directory may have its own sub directory, and so on. Does that matter? I am confused by recursive call if it involves several steps.


SOLUTION
Avatar of grg99
grg99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Come on, man. Why you appeared so late @@
Late?? just 12 hours after your posting? You are quite aware this is a forum, and not an IRC? ;)

Regards
Friedrich