473,414 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to build a folder tree structure?

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

Nov 16 '06 #1
4 7390
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
Nov 16 '06 #2
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);

}

Nov 16 '06 #3
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.
Nov 16 '06 #4
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.
Nov 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ragha | last post by:
Dear friends I am emulating thr tree structure mentioned in the article http://www.15seconds.com/issue/010921.htm I have succesfully created the folder structure for level 2 I need this...
1
by: jayesh | last post by:
Hi fellas! i need to implement a folder tree structure in .NET ..not really sure how to go about it ..if anyone could give me some tips and/or links to related sites it'd be great! thnx!
5
by: Lucas Ponzo | last post by:
I have the following directory structure: \images \other_images\images There is duplicate names, but at diferent levels. But the Visual Studio Setup Project emits the error: Unable to...
0
by: John H. | last post by:
In effort to understand (Outlook) MAPI folder tree structure wrote simple linear code below to navigate tree. Successive "...Folders.GetNext()"'s return same folder at all levels of tree. What...
0
by: hortoristic | last post by:
We currently have a solution up and working on VS 2005 and bound to source control VSS 6. I want to now add our DATABASE folder from VSS to our existing solution. My first approach has been...
2
by: graphicsxp | last post by:
Hi, I have the following records stored in the database : TableName: Folder { FolderID, FolderName, TopLevel} TableName: FolderRelationship { ParentID, ChildID} This describes a folder...
4
by: Sergei Minayev | last post by:
Hi All! Can you please help me with the following problem: I need to store a copy of local folders structure in MySQL database. I have chosen the following table structure for that:...
5
by: hankypan1 | last post by:
Hi All, I need a tree data structure for my application. It is the non -cyclic simple tree where i can have any number of children node and each child can recursively become a sub tree like a...
0
by: HarXon | last post by:
Hi, I am relatively new to C# and am attempting to implement the following: I currently have a text file containing the full path of all folders on a disk, from this i would like to create a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.