Unique Filename for Key Value Extraction

1 post / 0 new
Brian Element's picture
Brian Element
Online
Joined: 07/11/2012 - 19:57
Unique Filename for Key Value Extraction

I was creating a script using the Key Value Extraction and I wanted to use a unique filename.  In this test it takes a prefix (task.DbPrefix = "new filename") and will return the final filename.  I tried using the client.uniqueFilename which returns a unique filename but it this instance it doesn't like it because it also gives the path information and the extension so I came up with this work around.  I use the client.UniqueFilename and then remove the path information by using the iSplit function (a function available in the equation editor) and I then remove the extension by using the Left and Len functions.  Here is my code:

dbName = iSplit(client.uniqueFilename("IT T doc type"), "", "\", 1, 1) 'get only the filename
dbName = Left(dbName, Len(dbName) - 4) 'remove the .IMD file extension

and here is an example put together:

 


Function extractTDocType()
	Dim dbName As String
	Set db = Client.OpenDatabase("My File.IMD")
		Set task = db.KeyValueExtraction
			Dim myArray(1,0)
			myArray(0,0) = "T1"
			myArray(1,0) = "T2"
			task.IncludeAllFields
			task.AddKey "TYPE", "A"
			dbName = iSplit(client.uniqueFilename("New File"), "", "\", 1, 1) 'get only the filename
			dbName = Left(dbName, Len(dbName) - 4) 'remove the .IMD file extension
			task.DBPrefix = dbName
			task.CreateMultipleDatabases = FALSE
			task.CreateVirtualDatabase = False
			task.ValuesToExtract myArray
			task.PerformTask
			sNewFilename = task.DBName
		Set task = Nothing
	Set db = Nothing

End Function