Tech Support > Computers & Technology > Programming > Creating a directory using a partial path name
Creating a directory using a partial path name
Posted by Sigmathaar on December 5th, 2005


Hi I'm trying to create a directory without knowing his entire name. I
have someting like this :

root/.../something/mydir

My problem is that since I don't know what is in the "..." I can not
use the POSIX mkdir function.

I'm making an XML parser for the creation of an entire directory tree
on Windows. The program (not yet written) goes through an XML Schema
Instance to create some directories (about 5000).

While creating the directories the XML file that I'm parsing is
alphabetically ordered not hierarchically and I can't allow the program
to stock the path names for each brach on the directory tree.

The XML file looks something like this :

<Object>
<term>America</term>
<topTerm>Continents</topTerm>
<broaderTerm>Continents</broaderTerm>
<narrowerTerm>USA</narrowerTerm>
<narrowerTerm>Mexico</narrowerTerm>
</Object>
<Object>
<term>Colorado</term>
<topTerm>Continents</topTerm>
<broaderTerm>USA</broaderTerm>
<narrowerTerm>Denver</narrowerTerm>
</Object>
<Object>
<term>Continents</term>
<narrowerTerm>America</narrowerTerm>
<narrowerTerm>Europe</narrowerTerm>
</Object>
<Object>
<term>Denver</term>
<topTerm>Continents</topTerm>
<broaderTerm>Colorado</broaderTerm>
</Object>
<Object>
<term>USA</term>
<topTerm>Continents</topTerm>
<broaderTerm>America</broaderTerm>
<narrowerTerm>Colorado</narrowerTerm>
<narrowerTerm>Detroit</narrowerTerm>
<narrowerTerm>Los Angeles</narrowerTerm>
</Object>


The topTerm is the root of my directory tree, each term can have a
generic node (parent) and a specific node (child) without any limits of
depth. On the example we have :

Contients->America->USA->Colorado->Denver

This is the algorith we came with for creating the directory tree :

Get list of objects
Go to first object
While there are any objects
If topTerm != NULL
If directory "topTerm" exists
If directory "broaderTerm" exists somewhere in "topTerm"
directory
Create directory "term" in "broaderTerm"
Destroy object
End If
Else
Create directory "topTerm"
End If
Else
If directory "term" doesn't exist // If you are here term is
the root of the tree
Create directory "term"
End If
End If
Go to next object
End While

As you can see whenever I try to create a new directory I just have
partial path name, the mkdir does not work.

If somebody knows a way to find or create a directory using a partial
path name it will be very useful, if not I may change the algorith for
something less practical unless you got a better idea.

Tanks.

Posted by spinoza1111@yahoo.com on December 7th, 2005


Hmm, if it is infeasible to create an in-memory tree then devise a
temporary ID for each unknown path. Use a hash table to associate this
ID with at first an unknown and then a known value, and whenever an ID
is resolved to a known value, use the directory rename function to
rename the directory.

Sigmathaar wrote:


Similar Posts