How to get all the filenames in a folder and store them in a excel file.
strArray = Directory.GetFiles(folderpath)
save the array to excel.
Str [ ] = Directory.GetFiles(“FolderPath”)
The above one will give you array of string as output. Then use For Each loop activity to iterate that array and then use write cell activity to write into Excel file.
The names I am getting but while storing the names in a excel file,it storing only one file name, which is the last file in my folder.
Check whether the Add data row activity is inside or not…
Its inside the for loop bro
You can use a Assign activity to get the list of files and folders in a particular directory.
In the assign activity use the below code.
The output of this command is a String array. You can use another assign activity just below the one you already used and convert this array to a datatable which makes it easy to write to an excel.
Use the below code to convert it to a datatable
- Create a dataTable variable and assign it to a datatable object using New DataTable
- In the assign activity use the below code to convert the array to datatable
Now, use a Write Range activity to write the data to an excel file
Hope this helps
As I am new in UI Path,Can you do me a favor and provide me one sample Robot.
Thanks for your reply.
if possible can I have the xaml of yours, as it would easy to debug and come out with a solution @monishankar
DirectoryName.xaml (9.8 KB)
Bro this one i have created,which storing only one file in the excel file.
Use Append Range Activity instead of write range and put append activity outside the loop.
Thanks.Its working now, just instead of Write Range activity ,i have to use Append Range activity, and it should be inside the loop and not outside the loop.Thanks bro.
But if I run Robot for the second time,it writing names again ,keeping the previous values and I am getting duplicate values in excel file,which i don’t want.Do you have any idea for that…
Yeah, if you don’t want the same filenames, move the files once the bot will be completed. @monishankar
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.