How to get the first file stored in a folder?

Hi

String.Join("", Directory.GetFiles(PastaDownloadDocumentos,"*.pdf",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).lastwritetime.date = today))

This is what o mean?

Hi @Andre_Vieira

  • Don’t change the properties in “For Each File in Folder” Activity
    - Also use CurrentFile in the Read Pdf Files
    Refer the screenshot

I think, so it will work. can you check screenshot ?

1 Like

Hello, I’m getting

What variable type did you use?

Try LastWriteTime

LastWriteTime instead of GetLastWriteTime.

1 Like

If I can’t find another way I’ll try it again bro. Because I prever not working with loops

Hi @Andre_Vieira

You don’t want to use loops in your Activity.
Loops are works better in my opinion.

1 Like

I’m using:

String.Join("", Directory.GetFiles(PastaDownloadDocumentos,"*.pdf",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).Take(1))

With this expression, the robot is processing the last pdf in folder, in terms of arrival.
And I want to process the oldest one. :sweat_smile:

You can do it in one line query without looping…I will show you when I get back…

1 Like

Hi @Andre_Vieira

String.Join("", Directory.GetFiles(PastaDownloadDocumentos,"*.pdf",SearchOption.AllDirectories).OrderByAscending(Function(d) New FileInfo(d).LastWriteTime).Take(1))

Try this expression

1 Like

Hi,

That is the challenge as I said earlier with Creation and LastWriteLine when files are downloaded. What if you use Ascending? Do you get the expected, I am assuming it should because that will be the least distant time (last modified closest to Now).

1 Like

You right! I didn’t saw that coming. Maybe is better to work with loops :woozy_face:

@Andre_Vieira - Please check here…

My Files

image

OrderByDescending Using LastWriteTime - File3 sorted first

.First will read the first file…

If you want to read the first created file…then try this…

Is this what you are looking for??

1 Like

I have to test it here first :sweat_smile:
Can you please copy the expression and pass it to us please? I don’t want to miss any char.
Another question, what is your variable type?

@Andre_Vieira - Please test it…

 Directory.GetFiles("YourFolderName").OrderByDescending(function(x) new fileinfo(x).LastAccessTime).First

You have to assign it to StringVariable since we are using .First…it is not a array…You can see from the screenshot…

1 Like

@Andre_Vieira - Note: I haven’t used any file types here and did not search with in subfolders…

If you have those requirements, then you just have to use…

  Directory.GetFiles("YourFolderName","FileSearchPattern",SearchOption.AllDirectories).OrderByDescending(function(x) new fileinfo(x).LastAccessTime).First

Hi !! :grin:

image

Assuming that I want to get first the oldest file in the folder.
Using your example should be the file dated from 12:19

@Andre_Vieira - Please read my post again…i have provided solution for both …See the third one here…

Reason why the post is dragging is You have to pay attention and understand what we are showing and telling…if not issue will never get solved…

1 Like

Thank you, that expression is doing exactly what I want it :grin: Great work!!!

Regarding this post is dragging I can assume that you are not paying much attention as well my friend. Because I explained very well 2 or 3 times in this post what I really needed and you came up with 2 or 3 solutions at the same time including 2 that do the opposite. :grinning_face_with_smiling_eyes:

Sending screenshots from the expression can lead to multiple miss understandings.

You did a great job today no doubt. :grin:

Thank you :slight_smile:

Friend…The reason why I gave multiple solution is, I see lot of times people changes the requirement or they will come back and ask what if i want this? that??? that’s wherever possible sometimes I show them couple of options…It won’t hurt right??

There is a reason for this too…By this way you can type and see how to code and you will get a great feel when you finish typing and there is no error…This way your learning will be faster…

1 Like

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