Make a "project" a file itself that contains the list of the other files in the project. When you delete the project, you delete each of the files listed in this file, then you delete the project file itself.
I like to use XML for these kind of files - I use it a lot for files that contain parameters especially, and you can dump all kinds of information in them and use Qt's QDomDocument API to read and write it to or from C++ data structures. You can open it in a web page and see it pretty-printed or use Notepad++ or Visual Studio or some other text editor to edit it it if you want.
I will typically have a file that looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Project version="1000">
<ProjectFiles version="1000" count="3">
<ProjectFile version="1000" name="File1" path="/path/to/file" description="The first file"/>
<ProjectFile version="1000" name="File2" path="/path/to/file" description="The second file"/>
<ProjectFile version="1000" name="File3" path="/path/to/file" description="The third file"/>
<ProjectFiles/>
<OtherStuff version="1002">
<ThingUnderOtherStuff version="1001" name="Thing1" value="42"/>
<OtherStuff/>
<Project/>
<?xml version="1.0" encoding="UTF-8"?>
<Project version="1000">
<ProjectFiles version="1000" count="3">
<ProjectFile version="1000" name="File1" path="/path/to/file" description="The first file"/>
<ProjectFile version="1000" name="File2" path="/path/to/file" description="The second file"/>
<ProjectFile version="1000" name="File3" path="/path/to/file" description="The third file"/>
<ProjectFiles/>
<OtherStuff version="1002">
<ThingUnderOtherStuff version="1001" name="Thing1" value="42"/>
<OtherStuff/>
<Project/>
To copy to clipboard, switch view to plain text mode
A few important concepts here. First, every element (<SomeElement>) has a version number string. This is not a version number of whatever is inside the element, it is the format of the element itself. I always use an initial value of 1000, and each time I change the format of what is contained inside the element, I bump up the version number.
So say for the <ProjectFile> element I decide to add a "fileVersion" attribute that keeps the current version number of the file itself. The first version of the <ProjectFile> element doesn't contain this, so if I am reading in an older project, I first look at the version number for each element, and that tells me what I can expect to see in that element. I know if it is a version 1000 file, I won't find a fileVersion attribute, but if it is 1001 or later I will.
When my program saves the XML file, it is always saved with the current version of each element.
The second concept is that it is human readable. You can look at the file and see whether you have forgotten to include something or misspelled an element or attribute name when reading or writing.
Third, it is portable. You can read it on any OS. You can read it with any XML viewer, not just your program.
Fourth, if you want to get fancy, you can write XSLT scripts to transform the XML into a flat ASCII format or into HTML for a pretty web page display.
And fifth, you aren't limited to ASCII text content. If you have binary content you want to store, you can easily convert it to Base64-encoded text and save that and back on reading.
If you use Visual Studio, open one of the .sln or .vcxproj files in a text editor. You'll see that they are both XML-based, and that the .sln files is a list of all of the projects in the solution, and the .vcxproj is a very detailed description of the files in the project and how to build whatever the target is.
Bookmarks