I’m trying to develop a small solution to get the first file inserted into a particular folder…
So I can process them from the oldest to the newest.
This is what im using:
String.Join(“”, Directory.GetFiles(PastaDownloadDocumentos,“*.pdf”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))
Those are my pdf files:
In this case, I want to process in the first place the file from 12:58, but with my expression, I’m getting the file from 13:08.
Any ideas on what is wrong?
Any help is well appreciated, thank you
Just go to Activity panel ->click on filter → click on studio X
Just look it and let me know
Hello Goku, I really don’t know if I want a loop, because the loop will pull all files in the folder almost at the same time and I don’t want that because each file must be processed individually.
I just want the robot to go to the folder and pick the oldest file and that same file will be moved for a final location. So if i have a loop i will have to pull all the files at the same time and moved them all at the same time and process them all at the same time, and something will gone wrong xD
Sunds like a plan, let me test this. I’ll give you feedback soon
@Andre_Vieira - Instead of creation time…use lastwritetime.date = today and take first …
I’m getting some access issues now
It works, if I put a message box inside the loop, It will show me the path of the file that I want to process.
You then need the LastWriteTime for FileInfo
Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.
You can try this:
String.Join("", Directory.GetFiles(PastaDownloadDocumentos,"*.pdf",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).Take(1))
You also have to be aware of this issue where the LastWriteTime can be older than CreationTime :
c# - How can FileInfo.LastWriteTime be earlier than FileInfo.CreationTime? - Stack Overflow
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 ?
Hello, I’m getting
What variable type did you use?
LastWriteTime instead of GetLastWriteTime.
If I can’t find another way I’ll try it again bro. Because I prever not working with loops
You don’t want to use loops in your Activity.
Loops are works better in my opinion.
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.
You can do it in one line query without looping…I will show you when I get back…
String.Join(“”, Directory.GetFiles(PastaDownloadDocumentos,“*.pdf”,SearchOption.AllDirectories).OrderByAscending(Function(d) New FileInfo(d).LastWriteTime).Take(1))
Try this expression
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).