Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to build a folder tree structure?

Reply
Thread Tools

How to build a folder tree structure?

 
 
shuisheng
Guest
Posts: n/a
 
      11-16-2006
Dear All,

I'd like to build a structure similar to the folder tree which

1. Has a root.
2. Nodes can be folder or files.
3. Folder can contain folders and files.
4. Name of folders and files under a folder can not be same.

Anybody can give me some hint?

I appreciate your help.

Shuisheng

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-16-2006
shuisheng wrote:
> I'd like to build a structure similar to the folder tree which
>
> 1. Has a root.
> 2. Nodes can be folder or files.
> 3. Folder can contain folders and files.
> 4. Name of folders and files under a folder can not be same.
>
> Anybody can give me some hint?


class FolderEntry
{
std::string name;
public:
FolderEntry(std::string const&);
};

class Folder : public FolderEntry
{
std::vector<FolderEntry*> entries; // can be empty
...
void fillEntries(); // scanning the file system
};

class File : public FolderEntry
{
...
};

What other hints do you expect? Scanning folders and filling in
the 'entries' for any 'Folder' is platform-specific.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
PasalicZaharije
Guest
Posts: n/a
 
      11-16-2006
It is tree structure with parent and sibling hierarchy:

struct node
{
node* first_sibling;
node* first_child;
// other data (like it is file or folder, etc)
};

For tree:

root
app
test1
test2
src
frm
usr1
usr2
usr3

root will be first allocated node struct.
root->first_sibling will point to first node at same level (so it will be
NULL), root->first_child will point to 'app'. app node (let say anode)
will be like: anode->first_sibling point to src, anode->first_child point
to test1, and so ...

Most operation will be recursive:

void dump(node* n)
{
dump(n->first_sibling);
dump(n->first_child);

}



 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      11-16-2006
Victor Bazarov wrote:

> shuisheng wrote:
>> I'd like to build a structure similar to the folder tree which
>>
>> 1. Has a root.
>> 2. Nodes can be folder or files.
>> 3. Folder can contain folders and files.
>> 4. Name of folders and files under a folder can not be same.
>>
>> Anybody can give me some hint?

>
> class FolderEntry
> {
> std::string name;
> public:
> FolderEntry(std::string const&);


I'd add:

virtual ~FolderEntry() {}

> };
>
> class Folder : public FolderEntry
> {
> std::vector<FolderEntry*> entries; // can be empty
> ...
> void fillEntries(); // scanning the file system
> };
>
> class File : public FolderEntry
> {
> ...
> };
>
> What other hints do you expect? Scanning folders and filling in
> the 'entries' for any 'Folder' is platform-specific.


 
Reply With Quote
 
hhsaez@gmail.com
Guest
Posts: n/a
 
      11-17-2006
What you need here is a typical example of a Composite design patter.
As Victor explained, you'll need a base abstract class that handle
common operation (like a function that returns the size of the element)
and then derived classes for both files and folders (each class will
implement the size function by returning its actual size or the sum of
the sizes of each child).

Verifying that there are no duplicates in the same folder is trivial
here.

Rolf Magnus ha escrito:

> Victor Bazarov wrote:
>
> > shuisheng wrote:
> >> I'd like to build a structure similar to the folder tree which
> >>
> >> 1. Has a root.
> >> 2. Nodes can be folder or files.
> >> 3. Folder can contain folders and files.
> >> 4. Name of folders and files under a folder can not be same.
> >>
> >> Anybody can give me some hint?

> >
> > class FolderEntry
> > {
> > std::string name;
> > public:
> > FolderEntry(std::string const&);

>
> I'd add:
>
> virtual ~FolderEntry() {}
>
> > };
> >
> > class Folder : public FolderEntry
> > {
> > std::vector<FolderEntry*> entries; // can be empty
> > ...
> > void fillEntries(); // scanning the file system
> > };
> >
> > class File : public FolderEntry
> > {
> > ...
> > };
> >
> > What other hints do you expect? Scanning folders and filling in
> > the 'entries' for any 'Folder' is platform-specific.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
B+ Tree versus Ternary Search Tree Ramkumar Menon Java 2 08-16-2005 08:13 PM
SWsoft Acronis Disk Director Suite 9.0 Build 508, Acronis OS Selector 8.0 Build 917, Acronis Partition Expert 2003 Build 292, Acronis Power Utilities 2004 Build 502, F-SECURE.ANTI vIRUS.PROXY v1.10.17.WINALL, F-SECURE.ANTI vIRUS v5.50.10260 for CITRI vvcd Computer Support 0 09-25-2004 01:38 AM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57