Announcing the new Datavyu v1.4.0 with enhanced features, bug fixes, and a new video player for Windows!

We are in the process of migrating away from this forum—feel free to browse existing help topics. For new support inquiries, please reach out to us via email at [email protected]

I have modified the provided ComboExport script to fit my data, but I would like it to export the data from each Datavyu file into its own CSV file. Obviously I can do this individually by opening each OPF file separately and exporting it with the export function in the file menu or a different export script that I have written, but I would rather write a script so I can export all OPF files in a specified directory at once into their own CSVs.

If this is actually possible, how can I modify the script such that the output CSV filename matches the filename of the OPF being exported (e.g. 12340-05-01.opf is exported to 12340-05-01.csv)?

The way the script is written currently, it runs through all the files in the directory at once, but spits out the output into one continuous CSV file named whatever is specified in the output_file argument.

asked 01 Mar, 13:17

tcoheno's gravatar image

tcoheno
11335
accept rate: 0%


It's pretty simple to change it to do that—the output portion just needs to go inside the loop and the data array needs to be cleared after writing.

There's 4 lines to do the write at the end of the script (display message, open file, write data, close file). If you are comfortable editing the body of the script, just move those lines into the end of the big loop. If you are unsure of how to edit it, you can send the script to [email protected] and we can edit it for you.

permanent link

answered 02 Mar, 17:09

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
531126
accept rate: 14%

Thanks! The only issue I'm running into now is that the output file is overwriting itself every time it goes through the loop. Is it possible to change the output file name within the loop such that the output file name differs at each iteration of the loop? It would be best if the output name would be the same as the input name (with .csv instead of .opf, obviously). Thanks!

(02 Mar, 17:52) tcoheno tcoheno's gravatar image

Yes, you can use $db.getName() to get the name of the spreadsheet. It will return the name with .opf at the end so you can use gsub to replace it with .csv. For example: filename = $db.getName().gsub('.opf', '.csv').

It might be a good idea to add that to change the output_file parameter to be an output folder and then add the filename to the end of that folder path: outpath = File.join(output_folder, filename)

(02 Mar, 18:14) Shohan Hasan ♦♦ Shohan%20Hasan's gravatar image

And then substitute the outpath into the line that opens the file, in place of the output_file parameter

(02 Mar, 18:15) Shohan Hasan ♦♦ Shohan%20Hasan's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×25
×11
×2

question asked: 01 Mar, 13:17

question was seen: 690 times

last updated: 02 Mar, 18:15

powered by OSQA