How to copy the filenames from the folder to excel file

How to copy the filenames from the folder to excel file

Hey @prititit

  1. Assign a variable with type Array of Strings with

System.IO.Directory.GetFiles(Your path as string)

  1. Add BuildDataTable
  2. User For each row
  3. ‘Add data row’ activity to build a datatable using ‘Build Datatable’(or you could directly add to excel using write cell)
  4. Write range the datatable

You’re all done

hello @AMRITANShlal

What should I put in the add data row ?

hey @prititit
1)Check the DataType of path_all variable if its string
2)If its string then pass path_all to array Row

@prititit - Another simpler way…you can ignore the build datatable and add datarow…Just create a for each loop and Write Cell activity as shown below…

Directory.getfiles(“YourFolderPath”)

Here Idx is the index variable , which by default starts from 0. So I have used in a write cell activity as “A” +(idx+2).ToString, it will write the values from A2 and so on…

Output(Since its the write cell…you have to add the header manually in the excel file either before or after the file gets created)

Simple right…? Try and let me know…

Not working

Its write only one file name

@Aleem_Khan… I have already provided the screenshot where it writes all the filename. Follow all the steps i have mentioned.

1 Like

I am following the same step but its write one file name only could you please share me workflow

@Aleem_Khan - Yes, i can certainly share. But before that, could you please show workflow screenshot?

@Aleem_Khan - Please check my screenshot again for For Each setup and Write cell…as i suspected you did not followed all the steps…

  1. In the For Each - you have to declare the index variable…(its there on my screenshot)
  2. Instead of A1…you have to use as “A” + (index+2).tostring

please fix this. it will work.

So what is datatype of index variable by default its taking string

If you use Ctrl+K and enter that variable it will automatically create with right type. In this case it is integer.

1 Like

But its showing so error could please share workflow i really appreciate

FileNames_ToExcel.zip (41.5 KB) – Here you go…

Thank you so much

add file name in excel sheet.zip (37.4 KB) i check you workflow its working fine but i am following the same step but my workflow still showing error please check it attached the file