Export a List of Link Module Descriptors

Link Module Descriptors, aka linkset pairings, are stored in the parent folder of the source module. These determine which link module is used when creating links between two modules. This script loops through the current folder and recursively through subfolders and reports on the link module descriptors (LMD’s) it finds. Output is to a CSV file.

//  List Link Module Descriptors in Folder

/*
	Recursively scan the current folder or project and generates a list
	of Link Module Descriptors (LMD's).

	Output is to a CSV file. 

	Tony Goodman.
*/

pragma runLim,0  /* turn off timeout dialog */

DB  dbMain        = null
DBE dbeExport     = null
DBE dbeExportPath = null

Folder currFolder = null
Buffer  outBuf    = null

/************************************
	scanFolder
************************************/
void scanFolder(Folder f)
{
	LinkModuleDescriptor lmd

	Item   itm
	string s
	string t
	string l

	if (null f) return

	for lmd in f do
	{
		outBuf += fullName(f) ", " getSourceName(lmd) "," getTargetName(lmd) "," getName(lmd) "\n"
	}

	for itm in f do
	{
		if (null itm) continue
		if (isDeleted(itm)) continue

		if ((type (itm) == "Project") || (type (itm) == "Folder"))
		{
			scanFolder(folder(itm))
		}
	}
}

/************************************
	doClose
************************************/
void doClose(DB db)
{
	release(dbMain)
}

/************************************
	doList
************************************/
void doList(DB db)
{
	outBuf = create
    outBuf = ""

	string fName = get(dbeExportPath)

	Stream outfile = write(fName)

	outfile << "Folder, Source Module, Target Module, Link Module\n"

	scanFolder(currFolder)

	outfile << outBuf
	close(outfile)
	delete(outBuf)

	doClose(db)
}

/************************************
	MAIN
************************************/
currFolder = current Folder

dbMain = create("List Link Module Descriptors")

label(dbMain, "This utility exports a list of all link module descriptors\n" //-
              "Output is to a CSV file as follows:\n" //-
              "Folder, Source Module, Target Module, Link Module\n")

dbeExport     = field(dbMain, "Folder", fullName(currFolder), 50, true)
dbeExportPath = fileName(dbMain, "Report File", "C:/Temp/" name(currFolder) " Link Module Descriptors.csv")

ok(dbMain, "OK", doList)
close(dbMain, true, doClose)
realize dbMain

block(dbMain)

destroy(dbMain)
dbMain = null