How to get a dynamic folder path created at run time?

Good evening guys!

I built an automation that creates a folder at runtime to store a couple pdf files.

These are my created folders:

actually they are created in another location an then moved to a final location in the cloud with a new name like:

"Pré-Aprovação Credito " +NumeroProcesso + " " + now.tostring(“ddMMyyy_HHmm”)

image

Until here everything is fine. My problem now is, I have to alert the department that this folder was created by email. And inside that email i have to provide the direct path last created folder.

Did anyone achieve this in the past?
I just need to have some opinions or tips in how to achieve this.

Any help is appreciated.
Thank you guys

I would like to assist you. But I am not able to understand your requirement.

What is the condition to Identify the folder? Could you please brief?

1 Like

I so sorry if i can’t be more clear. But i tried my best, trust me :sweat_smile:

But let me try again:

Everytime I created a new folder it will have this format

"Pré-Aprovação Credito " +NumeroProcesso + " " + now.tostring(“ddMMyyy_HHmm”)

The only static elemente is:
> Pré-Aprovação Credito The remaing elements are added at run time, like the process number along site with date.

Since those elements are dynamic is hard to track with high precision the recently created folder path.

you mean the folder created at 16.28 from the screenshot below?

1 Like

Hi @Andre_Vieira,

Could you confirm if all these folders will always be created in the same directory?

If yes, then to go for recently created folder, you can fetch the folder details basis recent timestamp and then mail those details.

Lets say if for today’s run, some exceptions happened and no new folder was created so last folder in the directory may be from last day. In that case, you may want to add few more conditions wrt date check for that particular day.

Regards
Sonali

1 Like

Exactly, we can do that approach, by collecting the path from most recent folder created.

I cutted the seconds from the datetime string

Hello there!

Yes, all these folders will be created always in the same directory. That can occur 1 or more times in the same day.

Exactly, i think that can be the best approach for this scenario.

thank you for the advice

Hi @Andre_Vieira,

Glad I could help.

Attaching some more info below for your quick reference, might be helpful to customize per your requirement:)

you can try something like this:

DirectoryInfo latestfolder = new DirectoryInfo(path).GetDirectories("*",SearchOption.AllDirectories).OrderByDescending(function(d) d.CreationTime).First();

it will return the latest created folder(last modified) directory.
and to get folder name and with date of creation see the attached sample.

Reference: latestdirdate.xaml (5.2 KB)

Regards
Sonali

1 Like

Hello @sonaliaggarwal47,

Thats a very good start

image

It is showing the lastest folder created in that location :slightly_smiling_face:
Now I have to try to get that same folder path :grin:

Thank you a lot for your time @sonaliaggarwal47

No problem at all @Andre_Vieira

Let me know the results once you have tried all the stuff :slight_smile:

Regards
Sonali

1 Like

@Andre_Vieira - I will give your couple of codes, please see which one suits you…

  1. This will get recent folder created on that day…because it will check createtime equals today

    Directory.GetDirectories("YourFolderName").Where(function(x) new FileInfo(x).CreationTime.date = now.date).OrderByDescending(function(x) new fileinfo(x).CreationTime).First
    
  2. This will get you the recent folder created in the given path

    Directory.GetDirectories("YourFolderName").OrderByDescending(function(x) new fileinfo(x).CreationTime).First
    

Note: None of the above code will look for subdirectories, if would like just include “SearchOption.AllDirectories”. Also, above codes will fetch the files based on the createtime, if you want lastwritetime, replace the createtime with LastWriteTime.

Hope this helps…

1 Like

This is how the work is done. It is 1 am here in Portugal and I jumped from the bed just to test your code :hugs:

image

You are extremely talented young man.

Thank you so much for your time and also for spending some time to try to comprehend my questions.
Have a very nice day friend :handshake: :blush:

1 Like

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