Classic file types are no longer available for use as of January 2021. You can transition your classic files or download a PDF. Learn More

How to get number of files in SFTP listing?

Answered
0

Comments

8 comments

  • Jeff Hickey

    The output from the List Directory command will need to be modified a bit, otherwise the error you ran into will be hit. First, the List Directory output is almost in a useable CSV format expect for the leading and trailing brackets. After removing the brackets, the data can be queried in Advanced Query. So the steps are to use Create File with the output from List Directory, then two instances of Find and Replace to remove the opening and closing brackets from the Create File output. The resulting file (which should now contain "/FILEA-2021.csv","/FILEB-6361152.csv" given your example as original input) can then be passed into the Advanced Query command as mentioned above to get the row count.

    1
  • Jeff Hickey

    Hi Waldo, since you have transformed the data into a CSV, you could use the Advance Query command with the PRAGMA statement to get the table_info(). This will include the record count of the data.

    0
  • Waldo Nell

    Ok and if I do not convert it?  How do I ask a JSON array its length?  That would be even simpler.

    0
  • Jeff Hickey

    I don't think it would be simpler in Chains. I imagine you would need to do something a little more tricky like iterate over it to capture a count or split it into chunks. The simplest way that I am aware of is to transform it to a CSV and then use Advanced Query.

    0
  • Waldo Nell

    Thanks Jeff.  Last question - why did my approach fail?  The Array to CSV failed as per above so I cannot implement your solution without moving beyond it.

    0
  • Waldo Nell

    I am not convinced that would work.  I ended up doing below which does.  Unless you implied I do some kind of transpose query in Advance Query as I would need to then count the number of columns as you have not transposed the data.  My solution based on yours below for anyone needing to do something similar:

    0
  • Jeff Hickey

    Historically, I haven't ran into a case requiring a transpose. But glad you were able to get a working solution. 

    0
  • Bob Bedick

    Hey I know this is 2 years old, but the "key error in position 5" error is caused by using "." as the path in an array of flat objects. To convert the List Directory output array into a csv, you want to set the path to null/blank.

    0

Please sign in to leave a comment.