If you work with CSV files in UiPath you have seen the horror show where headers duplicate and duplicates pile up like guilt. This guide shows how to Read CSV into a DataTable apply a Keep filter and safely Append CSV so you do not create a Frankenstein file. It is short practical and slightly sarcastic because you will thank me later.
High level first so your brain does not explode. The main steps are simple and reliable:
dtInput
dtFiltered
Use the Read CSV activity and store results in a DataTable like dtInput
. Do not skip encoding checks and header validation. If your headers are spelled differently between files standardize them now. You want consistent column names and matching data types so Append does not turn into chaos.
Drag in the Filter Data Table activity and choose Keep rows mode. Define your column conditions or use a custom expression and send the result to dtFiltered
. This keeps only the rows you actually want and drops background noise. Think of it as selective amnesia for bad rows.
There are two pragmatic ways to append. Use an Append To CSV activity from a reliable package or open a StreamWriter
with append set to true and write rows manually. Either way check whether the target file exists and only write headers when the file is empty. That prevents header rows from multiplying like bad decisions.
dtFiltered
matches the target fileAfter appending read the target CSV back into a DataTable and compare row counts or better yet use a unique key column to dedupe. If you prefer a DataTable approach merge dtFiltered
into the existing DataTable with DataTable.Merge
and then call DefaultView.ToTable(true)
to remove duplicates. That gives you deterministic results and a clear path to automation nirvana.
Keep column order and data types consistent across source and target files. Apply a Distinct operation or use DefaultView.ToTable(true)
when you have duplicates. Log row counts before and after appends so you can audit what changed. And add small retries around file write operations because file locks are the universe saying no.
Follow these steps to build a compact UiPath automation that reads a CSV filters rows based on rules and appends new data while keeping headers tidy and preventing duplicate entries. It is the kind of tidy automation your future self will high five you for.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.