How to pick the files on current date from folder

Hello Everyone,

I need to process only the current date files from the folder, Below are the sample file names
XYSS_MC_XXX_YYYY_202008031234.csv
XYS_MC_YYYY_202008031234.csv
XsS_MC_YYYY_202008011234.csv

any idea pls - Thanks

Hi @Fresher

Refer the below thread that will help you to solve your query :-

Also another way is der as below :-

  1. Do this within Assign Activity

String filePaths = Directory.GetFiles(path)

  1. Within ForEach Activity do as below

For item in filePaths

  1. Use the below thing in If Activity

item.Contains(DateTime.Now.ToString(“yyyyMMdd”))

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

@Pratik_Wavhal -Thank you

Purpose : in a folder i need to take only the files with current date and need to add them in array of string for next process, but am getting below error when i fix the for each Type argument as string

if i convert the for each Type argument as object am getting below error

@Fresher You can do so with a Single Linq Query :

FilePaths = Directory.GetFiles(path).ToArray

TodaysFilePaths = FilePaths.Where(Function(x)x.Contains(Now.ToString(“yyyyMMdd”))).ToArray

Where FilePaths and TodaysFilePaths are Array Of String types

1 Like

Hi @Fresher

So while you are converting Type Argument as object for ForEach Activity then do as below :-

item.ToString.Contains(DateTime.Now.ToString(“yyyyMMdd”))

I forget to mention above der only :sweat_smile:

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

2 Likes

Thanks @Pratik_Wavhal and @supermanPunch : both of your workaround worked - Thank you so much

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