Open folder based on YEAR modified


I have a folder where are many folders named by year (2018, 2019, 2020,…) which also have sub-folders named by month (01, 02, 03,…) and these also have sub-folders named by date which then contain files. For this workflow I need to open the folder that is from current year, then open folder from current month, then open folder from today’s date and then read files. Files and folders are created every day automatically (files are sent from other party and automatically downloaded) so the robot needs to read files automatically when file arrives.

Hi @markosc – Please have a look…is this what you are looking for …

I have files inside Test\2021\03\18 → Folder…

StrGetTodayFiles = Directory.GetFiles(“Test”+now.ToString(“yyyy”)+" \ “+now.ToString(“MM”)+” \ " + now.ToString(“dd”))

Remove the additional spaces from above, that was added just to show the code here…

My Files


1 Like

Hi. Thank you very much that is working, but I forgot to mention I also have a sub-folder named as time when created but in format for example if the file is received at 12:05 it will be named “1205” and then I have to read files that are in this folder but only .xml files. Do you have any suggestions on how to do this? Thank you for your help!

@markosc - So you have files inside Test\2021\03\18 OR Test\2021\03\18\1205 OR both??

Please share some screenshot of the folders and files created today?

Also, how frequent the files created ??? Say 1205 1210 1215 like this?? if so how do you want to read files?? by time or by date???

I solved it, I created a new time variable and formatted it into “hhmm” and added that into GetFiles. Thank you so much for your help!

1 Like

@markosc - great…Please mark my post as solution , that will close this thread…

Hi, one more question. How do I get only the name of the files because string.Join is giving the full path?

@markosc - You do it two ways…

  1. StrGetTodayFileNamesOnly = New System.IO.DirectoryInfo(“Test”+now.ToString(“yyyy”)+""+now.ToString(“MM”)+"" + now.ToString(“dd”)).GetFiles().Select(Function(file) Path.GetFileName(file.Name)).ToArray

  2. You can do a for each loop(using Previously created variable)

1 Like

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