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
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Regards
Friedrich
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