How to get file Name using While loop and write into existing excel sheet

hi friends, can someone show me how to get file names from a folder using a while loop and write it into my existing excel sheet into a column without creating a new data column. I don’t want to use for each loop because my bot works well with while loop.

1 Like

Hi @Shazid_Rahman,

Please, take a look at the attached file

Main.xaml (6.8 KB)


If it solves your problem, kindly mark this post as solution to close this topic.

If you need extra help, please let me know :slight_smile:


1 Like

hi @Shazid_Rahman,

Kindly refer the solution provided by @gustavo.cervelin, and mark it is as solution if it solves your purpose, so that the thread can be closed.




1 Like

My pleasure @Shazid_Rahman

Just don’t forget to mark the answer that helped you the most as solution to close this topic


Don’t use a While loop. Just use Directory.GetFiles and it’ll put the list of files into an array.

Then For Each through the Array and add each filename as a row in a datatable. Then use Write (or Append) Range to write to Excel.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.