Page 1 of 1

Only export to CSV if not empty?

Posted: Wed Feb 23, 2022 3:42 pm
by yeti
Hi Juan,

Things are working well with my project.

Something else I am looking to achieve, which would improve the success rate of my results...

'If' there was an issue with the scrape, which resulted in an empty CSV - is there a way to make sure that the CSV is not exported?

Importing an empty CSV into my website would cause problems, as it is configured to delete data from the website that no longer exists in the CSV.

Thank you.

Re: Only export to CSV if not empty?

Posted: Sat Mar 05, 2022 8:09 am
by webmaster
I'm assuming you have a table that you don't want to export if it's empty? Supposing you have a table called Test, you can first create a query by right-clicking your table (Data.Test in this case) in Project Explorer, selecting Create Query, leaving everything with the default values and pressing OK. Then you can do this:

Code: Select all

Action.SequenceFirst
   ·  Sequence.Length
         ·  Sequence.First
               ·  Query.Test
as length
if
   ·  =
         ·  length
         ·  1
   ·  Action.ExportData
         ·  "Test"
         ·  "test.csv"
         ·  true
   ·  Action.Log
         ·  "Data was empty."
What that's doing is taking the first row in the query (this is just an optimization) and getting the length, which can be 1 if the table has contents or 0 if it's empty, and then exporting only if the length is 1.