cancel
Showing results for 
Search instead for 
Did you mean: 

Get Folders Action - with certain conditions

Hello,

I'm looking for an option to get all folders created before/after certain DateTime Or only get X number of folders based on ascending descending order. Kind of  direct filter before we get collection.

I have a target folder containing appx 1lac files and my first step is to get all this in a collection and then filter only required files for further operation.

My concern is System.OutOfMemory exception if this scenario goes to production.

Those 1 lac files will be there in target folder due to other tool dependency and it can grow in future. Meaning we have no solid control of archiving or deleting due to certain dependency.

I'm using Get Folders action as of now from Utility-File Management VBO.

So looking for some workaround or alternative.

------------------------------
Thanks & Regards,
Tejaskumar Darji
Sr. RPA Consultant-Automation Developer
------------------------------
3 REPLIES 3

PabloSarabia
Level 11
Hi @Tejaskumar_Darji

I duplicate and change little bit the "Get Folder" actio​n to create "Get Folder - Filter" action in the "Utility-File Management" VBO.

Find attached to this post.

For use it. Only need to put the two dates that you want to filter.

26853.png
I try it and works pretty good.


Hope this helps you!


See you in the community, bye 🙂


------------------------------
Pablo Sarabia
Architect
Altamira Assets Management
Madrid
------------------------------

I didn't see the upload error, sorry 🙂


Here you have the attachment 😄

------------------------------
Pablo Sarabia
Architect
Altamira Assets Management
Madrid
------------------------------

Hi Tejas,

Not sure if this will be able to solve the issue as I didn't test the same with 1 lac folders 😛

But well, you can give it a shot as I am using LINQ queries with Folder Retrieval as a part of the below custom code stage. I am using LINQ queries as it can speed up your collection filtering by miles.

You can create a new business object and add the below External References ('System.Data.DataSetExtensions.dll', 'System.Core.dll') and Namespace Imports ('System.Data.DataSetExtensions', 'System.LINQ', 'System.IO' and 'System.Collections.Generic') on the Page Description stage of your Initialize action for the LINQ queries to work properly. Also, ensure that the language is selected as 'Visual Basic':

26855.png
Once you have the updated code options as shown above, create a new action named 'Get Folders By Filters' and pass three input arguments, Folder Path (Text) and Start Date (Date) and End Date (Date). Based on the field names that you provide the unique records will be fetched from the Input Collection. Also, set an Output parameter as Folders (Collection) for this action as shown below:

26856.png

Add the code stage and use the below code with the input and out arguments as show:

Dim folderDir As New DirectoryInfo(Folder_Path)

Dim folder_enum = (From folder In folderDir.GetDirectories() _
Where folder.LastWriteTimeUtc.Date >= Start_date And folder.LastWriteTimeUtc.Date <= End_Date _
Select New With {.FolderName = folder.Name, .Path = folder.FullName, .Created = folder.CreationTimeUtc, .LastAccessed = folder.LastAccessTimeUtc, _
.LastWritten = folder.LastWriteTimeUtc})

Dim dt As New DataTable
dt.Columns.Add("Folder Name")
dt.Columns.Add("Path")
dt.Columns.Add("Created")
dt.Columns.Add("Last Accessed")
dt.Columns.Add("Last Written")

Dim dr As DataRow

For Each item In folder_enum

   dr = dt.NewRow
   dr("Folder Name") = item.FolderName
   dr("Path") = item.Path
   dr("Created") = item.Created
   dr("Last Accessed") = item.LastAccessed
   dr("Last Written") = item.LastWritten
   dt.Rows.Add(dr)

Next

Folders = dt


26857.png
The run results are as follows:

Input Arguments:

26858.png


Output Result:

26859.png

------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.