Search code examples
ibm-doors

Replicating DOORS structure in windows


I'm trying to create a script that will replicate a DOORS structure in a windows file structure. The idea is to run the script and have the folder structure from the current location downwards replicated in a windows folder structure of the users' choosing. I'm brand new to DXL but I've found the mkdir() function. When using it I seem to have problems when giving it a full filepath i.e. C:\output\folder1\ . In this case it would not create the structure properly unless C:\output already exists.

My question is, is there a way to make it so that multiple folder levels can be created at once, or is there a better way to go about it?


Solution

  • Steve's answer was correct, although in my case it made more sense to use recursion, due to some other stuff I also had to do.

    This code was modified from a version I found on the IBM Developer Works forum, but I cannot find the source, I'll link it if I find it again

    void  RecurseFolder(Folder fld)
    {   // Deal RECURSIVELY with sub-folders, and then all modules in this folder
    
        if (!fileExists_(g_base_dir "\\" name(fld)) && !(name(current) == name(fld)))
        {
            mkdir(g_base_dir "\\")
        }
    
        Skip skpItems = createString()
        Item itm
        string NameItem
        Folder fldNew
    
        // Stage in Skip, key is name which is Alpha order
        for itm in fld do
        {  
            put (skpItems, fullName(itm), itm)
        }
    
        // Recurse through sub-folders
        for itm in skpItems do
        {  
            string base_dir = g_base_dir
            NameItem = (string key skpItems)
            if (type(itm) == "Folder" or type(itm) == "Project")
            {  
                fldNew = folder(NameItem)
                g_base_dir = g_base_dir "\\" name(fldNew)
                RecurseFolder(fldNew)   // *** RECURSION ***
                g_base_dir = base_dir
            }
            else if    (type(itm) == "Formal")
            {
    
                //open module for reading - silent mode, standard view
                Module m = read(fullName(itm), false, true)
                if (NameItem != "")
                {
                    if (!null export(base_dir "\\" name(itm) ".xml"))
                    {
                        errorBox "Export failed! - \n" base_dir "\\" name(itm) ".xml"
                    }
                }
    
                //if module is not visible
                if (!isVisible(m))
                {
                    // close it to improve performance
                    close m
                }
            }
           else {} //Nothing to do
        }
        delete(skpItems)
    } // end RecurseFolder()