Finding a directory using a partial path name

Discussion in 'C++' started by Sigmathaar, Dec 5, 2005.

  1. Sigmathaar

    Sigmathaar Guest

    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.
     
    Sigmathaar, Dec 5, 2005
    #1
    1. Advertising

  2. Sigmathaar

    mlimber Guest

    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-lite/how-to-post.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
     
    mlimber, Dec 5, 2005
    #2
    1. Advertising

  3. Sigmathaar

    Sigmathaar Guest

    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?
     
    Sigmathaar, Dec 5, 2005
    #3
  4. Sigmathaar

    Sigmathaar Guest

    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??
     
    Sigmathaar, Dec 5, 2005
    #4
  5. Sigmathaar

    Ben Pope Guest

    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...
     
    Ben Pope, Dec 5, 2005
    #5
  6. Sigmathaar

    mlimber Guest

    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
     
    mlimber, Dec 5, 2005
    #6
  7. Sigmathaar

    Sigmathaar Guest

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

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Singer
    Replies:
    0
    Views:
    564
    Steve Singer
    Feb 15, 2005
  2. Billy
    Replies:
    2
    Views:
    528
    Billy
    Feb 1, 2006
  3. RonS
    Replies:
    5
    Views:
    4,458
  4. Thomas Heller
    Replies:
    13
    Views:
    893
    Michele Simionato
    Feb 8, 2007
  5. J. Clifford Dyer

    Re: Partial 1.0 - Partial classes for Python

    J. Clifford Dyer, Feb 8, 2007, in forum: Python
    Replies:
    0
    Views:
    538
    J. Clifford Dyer
    Feb 8, 2007
Loading...

Share This Page