Get files from the latest folder created in a directory

hi guys!
i have a folder that contains many folder inside of it
im trying to open the latest folder created based on the creation date and then open the excel files listed inside. any thoughts?

i used this expression to get the name of the latest folder created based on the creation date and it gave me the folder name back, only the name not the full path and it’s stored into a variable of type “directory.info”

variable name is “name”
{New DirectoryInfo(“my path”).GetDirectories().OrderByDescending(function(d) d.CreationTime).First()}

next step is to open the folder and get the files inside of it but since the variable type has to be directpry.info i cannot add the variable to a getfiles attribute

i tried to use
{directory.GetFiles(“my path”+name.ToString)}

while “name” is the variable that i used to get the latest created folder

unfortunately the “name” variable gives me the latest created folder’s name and there’s no issue with it but when i try to use that variable as a part of the directory path like i did up there in the second code it didn’t work …

thanks all

@kamal_hamad I have tested your code and it seems to be working fine. I think you might miss a \ between “my path” and name.ToString. The safest way to do it is to use Path.Combine.

Files = Directory.GetFiles(Path.Combine("C:\MyFolder",name.ToString))

You can also get the full path using name.FullName instead.

Files = Directory.GetFiles(name.FullName)

image

1 Like

that worked just fine!
appreciate ur response sir thanks a loottttt

1 Like

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