473,394 Members | 1,841 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,394 software developers and data experts.

Finding a directory using a partial path name

Hi, while making an XML parser for the creation of an entire directory
list I got this problem and I'm having trouble solving it. 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,I can't use the usual mkdir POSIX function and this
for every directory exept the root. If somebody knows of a fonction
that allows to find a directory using a partial path name I could use
it to create the directory tree, if not I may change the algorith for
something less practical unless you got a better idea.

Tanks.

Dec 5 '05 #1
6 1964
Sigmathaar wrote:
Hi, while making an XML parser for the creation of an entire directory
list I got this problem and I'm having trouble solving it. The program
(not yet written) goes through an XML Schema Instance to create some
directories (about 5000). [snip]

All this is off-topic here. See the FAQ for what is on-topic:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
As you can see whenever I try to create a new directory I just have
partial path name,I can't use the usual mkdir POSIX function and this
for every directory exept the root. If somebody knows of a fonction
that allows to find a directory using a partial path name I could use
it to create the directory tree, if not I may change the algorith for
something less practical unless you got a better idea.


You might look into Boost's filesystem library
(http://boost.org/libs/filesystem/doc/index.htm). Not sure if it will
do what you want, as I didn't wade through your post in detail.

Cheers! --M

Dec 5 '05 #2
mlimber wroter :
All this is off-topic here.


I don't get you, why is my post off topic? The question is about C++
not XML, my problem basically is that I can't use the POSIX mkdif
function since I don't know the entire path name of the directory I
want to create.

Can you explain me why do you think my post is off topic?

Dec 5 '05 #3
mlomber wrote :
All this is off-topic here. See the FAQ for what is on-topic:


I don't get you, why is my post of topic? I've read the FAQ and I don't
really see any problem in my topic. The question is not about XML, it's
about C++, 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. Can you please explain me why do you
think my post is of topic so I can't go somewhere else to get help with
my problem??

Dec 5 '05 #4
Sigmathaar wrote:
mlomber wrote :
All this is off-topic here. See the FAQ for what is on-topic:
I don't get you, why is my post of topic? I've read the FAQ and I don't
really see any problem in my topic.

From the cited FAQ: "[Y]our question must be answerable by looking into the C++ language definition as determined by the ISO/ANSI C++ Standard
document, and by planned extensions and adjustments."
The question is not about XML, it's about C++,
Actually, it's about doing something that the standard C++ language
doesn't innately support, so it's *not* about C++ proper, which is the
sole topic of this newsgroup. (Of course there is some leeway, but
algorithms like the one you posted are generally also outside the scope
of this group.)
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. Can you please explain me why do you
think my post is of topic so I can't go somewhere else to get help with
my problem??


This is a much simpler description of the problem, and it is probably
what you should have posted in the first place. You could always add
detail if it is needed. However, it is still off-topic in this C++
*language* forum, but here's a brief answer:

You can't access a file or directory by absolute pathname if you don't
know the whole path. It's simply non-sensical to try. You might
consider using relative pathnames instead by changing to (or storing)
each subdirectory as it comes up.

Try comp.programming or an OS-specific newsgroup if that doesn't
suffice.

Cheers! --M

Dec 5 '05 #5
Thanks for the answer, I guess it is off topic, I'll try to find some
help somewhere else.

Dec 5 '05 #6
Sigmathaar wrote:
mlimber wroter :
All this is off-topic here.


I don't get you, why is my post off topic? The question is about C++
not XML, my problem basically is that I can't use the POSIX mkdif
function since I don't know the entire path name of the directory I
want to create.

Can you explain me why do you think my post is off topic?


POSIX extensions are off-topic.

This group is for C++ language issues. Unfortunately external libraries
are not topical. Boost is an oft mentioned library here, but it's
specifics are also off-topic.

HTH

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Dec 5 '05 #7

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

Similar topics

4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
11
by: Fuzzyman | last post by:
What's the best, cross platform, way of finding out the directory a script is run from ? I've googled a bit, but can't get a clear answer. On sys.argv the docs say : argv is the script name...
1
by: Bruce | last post by:
I am writing an installer that needs to put a dll file with a bunch of extended stored procedures in the BINN directory. The problem is that if the machine is running multiple instances of SQL...
8
by: Mr. B | last post by:
I'm writing an app where I'm trying to look for and List all specific file 'types' found. So I point to a specific start top level Folder... and I want to drill down through ALL sub folders to...
22
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents...
8
by: James Owens | last post by:
I'm a relative newbie, interested in storing the information from several server directories and subdirectories in XML so that I can present it selectively using XSL (all files updated today or...
8
by: Rick Strahl [MVP] | last post by:
Hi all, I'm building an app that uses the ASP.Net runtime... One problem I've run into is that pages running inside of the runtime are not finding DLLs in the GAC. In fact, if I look at the...
4
by: m | last post by:
Hello I need to find out full URL of my application name, I tried using Request.ServerVariables but it returns only serverername, and I need virtual directory name as well. Thnx in advance
8
by: Joshua J. Kugler | last post by:
So, I have: ModTest __init__.py AModule.py BModule.py CModule.py All works fine. However, when I import ModTest, I would like it to discover and store the names of the modules beneath it,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.