Removing separator declaration from CSV file

csv

#1

Hi,

Tried to google answer,but couldn’t find it.

So I have a problem with .csv files. I’m downloading reports in .csv format from a system. Problem is that these .csv files include declaration row for Excel (first row is “sep=;”), this makes it so that the UiPath Read CSV activity gives an error: Read CSV : The CSV file format for FILEPATH\FILE.csv is invalid

When I remove the first row manually Read CSV activity works. I can ofcourse remove the rows by opening the csv files on notepad and deleting the first row, but I was wondering if there is a more elegant way. So my question is that is there a easier way to either ignore the declaration on .csv file or delete the first row?

And before anyone asks no it’s not possible to get the .csv files without the Excel separator declaration from the system.

Thanks!


#2

Hello,

You can use Read Text File activity and remove the first line, save the changes using Write Text File activity and then use the Read CSV activity. Or you can just use Read Text File activity, remove first row, and then use Generate Data Table activity to generate a DataTable from the string (assuming you want to have the contents of the csv file as a DataTable to do some more work).


#3

Hi,

Thanks! Didn’t think of that. That should work


#4

Hi Stan,

Do you know how to remove the first line in text file?

Thanks


#5

Hello,

Assign the following to the string variable resulted from Read Text File activity:

Split(strVariable, Environment.NewLine, 2)(1)

This splits the string based on the new line character in two parts, the first one containing the first line of the file and the second part containing the rest, and then retrieves the second part.


#6

Awesome! thanks a lot.