Skip to main content

create rdf file for CSV import

Hi, 
I am trying to import a csv file using an ideascript. I understand that there needs to be a corresponding rdf file otherwise the import wont work. Is there a way to create the rdf file using ideascript?
thanks,
 
Mike

klmi Fri, 10/11/2019 - 02:35

Hi mikew,
the easiest way to create the rdf file would be to import the csv file one time manually. As one of the last steps you will be able to save the rdf file. If you are using IDEA 10.4 (and higher) otherwise have a look on the CSVDefinition-Object.

mikew Fri, 10/11/2019 - 04:21

In reply to by klmi

thanks klmi!!
I was hoping to write a script that could import say all csv files in a folder rather than having to manully import each file. Is this not possible?

klmi Fri, 10/11/2019 - 06:21

I didn't write that's not possible to do such batch imports with IDEA however your question above referred only to the creation of the rdf file!
 
As you wrote you would need a rdf file as import definition. You can create that rdf file manually and then use it with your script for multiple imports. Regardless to say that all csv files should have the same structure because if not a script really makes no sense.
 
If you don't want to create the rdf file manually the CSVDefinition-Object gives you the opportunity set delimiters and so on by your code.
 
When it comes to the batch import of all files from a given folder the Dir-Object will help you in this project.

mikew Fri, 10/11/2019 - 10:05

thanks, apologies for the confusion. I am very new to using IDEA. Is there documentation somewhere that tells me how to use CSVDefinition-Object or the Dir-Object?
thanks for your help

klmi Fri, 10/11/2019 - 12:17

Yes there is! Have you ever tried IDEA's online help / object catalogue? There you will find an example to the object methods. 

mikew Wed, 10/16/2019 - 02:19

Hi klmi, thanks for your help. I have not been able to find an object catalogue or CSVDefinition-Object. I have tried to find this in IDEA Help (language explorer) as well as support.casewareanalytics.com (which I assume is the online help?). If you could point me in the right direction that would be extremely helpful?
thanks again,
Mike

Brian Element Wed, 10/16/2019 - 08:03

In reply to by mikew

Hi Mikew,

You can only create an RDF through script with version 10.4 or higher.  If you want to perfrom an import of a CSV with a version prior to 10.3 then you will have to first manually create the RDF file.

In the language browser, if you have 10.4, here is some example code for creating a RDF file.  It is under the CSV Definition object.

 


Sub Main

	csvPath = "Source Files.ILB\Delimited.csv"
	rdfPath = "Import Definitions.ILB\Delimited.RDF"
	firstRowAsFieldNames = TRUE
	CsvEncodingUTF8 = 2

	' Create, configure, and save the definition file.
	Set csvDefinition = Client.NewCsvDefinition
	csvDefinition.DefinitionFilePath = rdfPath
	csvDefinition.CsvFilePath = csvPath
	csvDefinition.FieldDelimiter = ","
	csvDefinition.TextEncapsulator = """"
	csvDefinition.FirstRowIsFieldNames = firstRowAsFieldNames
	csvDefinition.CsvFileEncoding = CsvEncodingUTF8
	Client.SaveCSVDefinitionFile csvDefinition
	
	' Define the output name and perform the import task.
	dbName = "Delimited.IMD"
	Client.ImportUTF8DelimFile csvPath, dbName, FALSE, "", rdfPath, firstRowAsFieldNames
	
	' Open the result.
	Client.OpenDatabase (dbName)

End Sub