Trying to get a row count of a CSV file and I’m getting the below compiler error. What am I doing wrong?
Error in Properties Screen
Variable setup as system.data.data.table
Trying to get a row count of a CSV file and I’m getting the below compiler error. What am I doing wrong?
Error in Properties Screen
Variable setup as system.data.data.table
Hi,
Can you try to use ReadCSVactivity instead of GetFileInfo?
Regards,
So this is what I’m trying to do. My project is reading a .csv file. IF the .csv file is empty, that means there is no processing that needs to be completed.
I previously had setup an if statement, but it never seemed to work even if the .csv was empty. My condition was if the datatable was not nothing, then log and proceed process. If data table is nothing, my else statement never seemed to come into play. What would be the correct way to express this condition?
Hi,
Can you try as the following?
First Get FileInfo using GetFileInfo activity (Let’s say fi )
Then check fi.length
Regards,
Follow below steps ,
HAPPY AUTOMATION !!!
I appreciate your help. I’m having a terrible time getting this project to run. Basically i know there is a CSV file in the file path, but I also know that this csv file is blank. I’ve tried the suggestions above to no avail. I know that the exact failure point is the sequence below. When the referenced file contains data, the process works correctly. When the file is empty, I consistently receive the “Reading Inventory File” log message immediately followed by an error message of “Process failed: UiPath.UiAutomation.Activities due to: Value cannot be null. Parameter name: source” and then the transaction ends and I do not receive the “Reading inventory file - complete” message, which leads me to believe the read csv is the failure when the file is empty. I’ve also used a try catch and that doesn’t work for me either. Is there any hope for a better solution? I’m still fairly green at using UI Path and appreciate your super quick responses!
Hi ,
The reason behind your errors are, 1. File might be empty , and 2. File itself is not available. The Screenshots i’ve shared will handle these two cases. So, i would suggest you try the way i;ve suggested . If you find any difficulties please send a sample CSV i will provide the XAML.
HAPPY AUTOMATION !!!
Hi @kasey_v ,
Have you tried using Try Catch
Activity to Catch that Specific Exception that arises when the File is Empty (When using Read CSV Activity)?
We can then Handle it in the Catch block by intialising the Datatable variable to a new Datatable.
However, You could Check if File Exists at first and then perform this operation.
Hello @kasey_v ,
Suggesting to first use Read CSV activity and you will get a Datatable output.Suppose it is DT.
Then Use DT.Rows.Count to get the number of rows present in the csv.
Then you can put an if condition to check whether the count is >0. If >0, then you can do the actions. Else skip.
Is there any other complexity for this process?
I did try a Try Catch, but i can’t find a specific “Value cannot be null” exception.
@kasey_v ,
Try using the Below :
Will the Path Exists work if the file name can vary depending on the predetermined job? There’s code written much earlier in the project that guides this, and I am not positive how the entire workflow runs.
@kasey_v , Not exactly sure what you mean.
But if the File Path is in a variable and that is the same variable used in Read CSV File
Activity, then you could use the same variable or File Path in the Path Exists
Activity.
I would suggest, if you are okay please send a sample template of how the file looks. And then we suggest a workflow for you.