[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: [despammed] Best way to recursive folders?
From: Esben Mose Hansen <esben () despammed ! com>
Date: 2003-05-03 7:38:06
[Download RAW message or body]
On Saturday 03 May 2003 02:41, Mosfet wrote:
> Okay, I got a C function that creates or removes thumbnails recursively.
> Since it has a lot of local variables like the dir structures and such it
> can get pretty expensive if you have many depths of recursion.
>
> For this reason I'm thinking of doing a smaller recursive loop that just
> adds folders to process to a single linked list. Then when doing the actual
> processing I'd go through the list iteratively. This would be less memory
> intensive but would require more file processing since your scanning dirs
> twice: once recursively to load up the list to processes and then when your
> processing the resulting list iteratively.
>
> Any suggestions on the best way to handle recursive directory processing?
You can combine the above approaches: When scanning the first directory, push
any directories to a stack. When done with this directory, take the top
directory and process that in the same way. As this is tail recursion, it can
be replaced with a simple look. In psedo code, in pseodu C++:
stack<Directories> dirs_to_be_processed;
do {
for each file in diretory{
if (file is a directory)
dirs_to_be_processed.push(file);
processFile(file);
}
} while (!.stack.empty())
This kind of approach often works like a charm when you want to rid yourself
of those nasty recursions :-)
--
regards, Esben
esben@despammed.com *---* http://home.worldonline.dk/~mesben
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic