Topic
2 replies Latest Post - ‏2014-04-08T18:35:36Z by llandale
KBSri
KBSri
104 Posts
ACCEPTED ANSWER

Pinned topic How to loop through all the modules in the different folders

‏2014-04-08T04:44:08Z |

Hello All,

Please let me know how to loop through all the modules in the different folders.

And obtain the module name and their corresponding folder name

For eg: I run the script from the FOLDER-'CUSTOMER REQUIREMENT' which has different folders in it likes "SPECS","REQ","TEST"

The FOLDERS "SPECS","REQ","TEST" has different modules.

I need to get the output as FOLDER NAME and their corresponding MODULE NAMES.

  • Martin_Hunter
    Martin_Hunter
    40 Posts
    ACCEPTED ANSWER

    Re: How to loop through all the modules in the different folders

    ‏2014-04-08T05:52:43Z  in response to KBSri

    You will need to use a recursive function, something like this.

    /**
    * This function searches through the specified folder / project and
    * builds a skiplist of formal modules.  If bSub is true then all 
    * subfolders will be included.
    */
    void searchFolder (Folder fldr, Skip &skpData, bool bSub, int &noOfModules)
    {
        Item itm
        string itmName
        
        for itm in fldr do
        {
            itmName = fullName itm
         
            if (type itm != "Folder" and type itm != "Project")
            {
                if (null module itmName) {continue}
          
                if ((type itm) != "Formal") {continue}
          
                noOfModules++
                put (skpData, itmName, itmName)
            }
      
            else if (bSub)
                searchFolder (folder itmName, skpData, bSub, noOfModules)
        }
    }
    

     

    Updated on 2014-04-08T06:06:26Z at 2014-04-08T06:06:26Z by Martin_Hunter
  • llandale
    llandale
    2943 Posts
    ACCEPTED ANSWER

    Re: How to loop through all the modules in the different folders

    ‏2014-04-08T18:35:36Z  in response to KBSri

    I think you want to process all the modules of a folder, before you recurse sub-folders.  I think also you'd prefer to deal with them in Alpha order.

    • void RecurseFolder(Folder in_fld)
    • {  if (null in_fld) return
    •    Item itm
    •    Folder fld_Sub
    •    Skip skpItems = createString()   // KEY 'string' nameItem; DATA 'Item'
    •    for itm in in_fld do
    •    {  if (isDeleted(itm))      then continue
    •       put(skpItems, name(itm), itm)
    •    }
    •            // deal with Modules
    •    for itm in skpItems do
    •    {  if (type(itm) == "Formal")  then DealWithModule(itm)
    •    }
    •           // recurse sub-folders
    •    for itm in skpItems do
    •    {  if (type(itm) == "Folder" or type(itm) == "Project")
    •       {  fld_Sub = folder(fullName(itm))
    •          RecurseFolder(fld_sub)     // ** RECURSION **
    •       }
    •    }
    •    delete(skpItems)
    • }   // end RecurseFolder()