For each item in array


#1

Hi all,

I have a folder on my desktop and I would like to get the filenames listed in an excel file.
Currently I have an assign activity where variable fileList = System.IO.Directory.GetFiles(“C:\Users\XXX\Desktop\YYY)”

I defined the FileList variable as an array of strings.

I am now struggling to get them listed in an excel file.
I tried using “for each” (for each item in fileList) but then I am kind of stuck… should I use the activities “write cell/write range”? If yes what range do I have to specify if I want it to loop and enter all filenames one by one, on a new excel row?

Thanks in advance,
Kind regards


#2

Hi @yannip,
You can use the write range. But before that

1.Use the Build data table activity with one Column name
2.Inside the for each add the row data by using of Add data row activity .
3.Finally use the write range activity to write into an excel file.

Regards
Balamurugan.S


#3

You can also use read cell.
Please find the attached workflow.Directory_test.zip (2.8 KB)


#4

Thanks @Prashant_08 Prashant_08!! Works as expected. This was exactly what I was doing but I was not aware of how to add the counter…

@balupad14 thanks as well, I was trying but was missing something in the add data row step I think. It works with the solution above from Prashant_08.


#5

@Prashant_08 any idea how I can get only the filename and not the complete path?


#6

you can do that by string manipulations


#7

http://www.dotnetcurry.com/csharp/189/csharp-string-substring-split-functions


#8

Hi @yannip,

This is the steps which i have explained you. And It will return the file name only…

Here is the source : Directory_test.zip (2.9 KB)