create rdf file for CSV import

9 posts / 0 new
Last post
mikew
Offline
Joined: 09/25/2019 - 08:25
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
Offline
Joined: 02/13/2019 - 08:41

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
Offline
Joined: 09/25/2019 - 08:25

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
Offline
Joined: 02/13/2019 - 08:41

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
Offline
Joined: 09/25/2019 - 08:25

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
Offline
Joined: 02/13/2019 - 08:41

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

mikew
Offline
Joined: 09/25/2019 - 08:25

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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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 
mikew
Offline
Joined: 09/25/2019 - 08:25

thanks Brian, this explains my issue. I have an earlier version of IDEA!