Inventory of Items

This simple script loops through the current folder and recursively through subfolders and reports on the modules it finds. Output is to a CSV file. To produce an inventory of modules in the entire database, just run this script from the database root folder.

// Generate Inventory of current Project

/*
*/

pragma runLim,0 

Buffer outBuf = create
outBuf = ""

/**********************************
	scanModule
***********************************/
void scanModule(Item itm)
{
	Module thisModule = null
	bool opened = false

	string mName = fullName(itm)

	if (!open(module mName))
	{
		thisModule = read(mName, false)
		opened = true
	}

	outBuf += mName ","
	outBuf += thisModule."Created On" ","
	outBuf += thisModule."Created By" ","
	outBuf += version(thisModule) ","
	outBuf += thisModule."Description" ","
	outBuf += uniqueID(itm) "\n"

	if (opened)
	{
		close(thisModule)
	}
}

/*********************************
	scanFolder
**********************************/
void scanFolder(Folder f)
{
	Item itm

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

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

/************************************
	MAIN
*************************************/
string currFolder = fullName current Folder

if (confirm("Generate inventory for " currFolder "?"))
{
	scanFolder(folder currFolder)

	string fName = "c:/temp/inventory.csv"
	Stream outfile = write(fName)

	outfile << "Module Name,Created On,Created By,Version,Description,Unique Id\n"
	outfile << outBuf
	close(outfile)
	delete(outBuf)
	// notify the user that the script is complete
	ack "Inventory Complete."
}