classic question

M

mosfet

Hi,

Recently I wrote some classes to list process, copy recursively files,
delete files , ... and I have noticed that some part are common.

For instance, copying or deleting folders always means to do a recursion.
So my question is how can I maximize common code ?
Let's say I want to implement a recursive copy dir and delete dir ...
 
G

Gianni Mariani

mosfet said:
Hi,

Recently I wrote some classes to list process, copy recursively files,
delete files , ... and I have noticed that some part are common.

For instance, copying or deleting folders always means to do a recursion.
So my question is how can I maximize common code ?
Let's say I want to implement a recursive copy dir and delete dir ...

Think of scanning a directory as a stream of messages with filenames
which can be files or directories. Sometimes you want to traverse depth
first (for delete) or top down (for copy).

Your recusrive delete simply initializes the scanner and reads the
messages one at a time.

I did some experiments with parallelized recursive copies (hardlinks
actually). On a build machine (on windows) we would copy the subversion
tree (using hard links) on the automated build machine and it took quite
some time for a large tree. Using multiple threads did save some time.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi,

Recently I wrote some classes to list process, copy recursively files,
delete files , ... and I have noticed that some part are common.

For instance, copying or deleting folders always means to do a recursion.
So my question is how can I maximize common code ?
Let's say I want to implement a recursive copy dir and delete dir ...

You could make a function that traverses the directory and make it take
an argument which is a functionpointer/functor which it applies to each
element. Search for the visitor pattern, it fits your problem quite nicely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,539
Members
48,274
Latest member
HowardKipp

Latest Threads

Top