How to separate file paths and put them in a datable

  1. a/b
  2. a/b/sss.txt
  3. aaa/bbb/ccc/ttt_zz.txt

after DataTable>
a | b
a | b | | sss.txt
aaa| bbb | ccc | ttt_zz.txt

One simple thing you could try is to split the path by “/”, and then add the array entries to you DataTable.

Would be something like this:
PathVar = "aaa/bbb/ccc/ttt_zz.txt"
PathArrayVar = PathVar.Split("/")
for each item in PathArrayVar {
// add DataRow to DataTable with item as the value of the DataRow
}

But I’m worried about the variety of separate text bookings.

str = path.split

a/b : str(0), str(1)
a/b/c : str(0), str(1), str(2)

You mean like the array could get too long?

I don’t know if there’s a direct way to insert the array data to a DataTable without any iteration

Hi @sumouse

Strvar=path.getfilenamewithoutextension(filepath)

Thanks
Ashwin.S

Hi @sumouse

You can split the file path using the below code
FilePath.Split("/"c)

This will generate an array of items that contain all the folder names involved in the path.

Then you can use a for each activity to loop through the array to access each folder of a path. So as you said, since the number of folders may differ from path to path, before inserting to the data table, you will need to check whether it has the required number of columns in it.

So within for the each row, have a counter that increment from 0 to the very end. Then, use a try catch activity to check and assign the value to column. Why use try catch is because it will throw an error if the column does not exist. Column check can be done using the counter variable.

If it throw an error, within the catch segment we can add a add data table column activity and then insert the value…

1 Like

thanx…i will try

1 Like