Hello everyone!
I’m Brazilian, so I used Google Translate to be able to transcribe the message to everyone.
This is being my first post on the forum as I haven’t found any solution to my problem. =/
I’m developing an automation where I need to get from a directory only the files that were added today, either by creation or modification date (files are created and sent to the folder on the same day, so the creation and modification date will always be the same).
Currently, the closest I’ve come is:
Directory.GetFiles(“C:\Temp”).Where(Function (f)Directory.GetCreationTime (f).ToShortDateString = System.DateTime.Now.ToString("dd/MM/yyyy ")).ToArray
However, when I run the automation, nothing happens.
One reason might be, that .ToShortDateString does not have the format “dd/MM/yyyy”.
Because for me it doesn’t, for me it’s “MM/dd/yyyy”.
You can easily check it by getting all files with Directory.GetFiles(“C:\Temp”)
and then looping through them, printing the dates like so:
Directory.GetCreationTime(file).ToShortDateString +" vs " + System.DateTime.Now.ToString("dd/MM/yyyy ")
This is my result:
Other than that, I wouldn’t recommend doing this by comparing strings but rather by comparing the actual dates so it doesn’t matter which format a date is in.
However, the directory contains more than 3,500 files, making the “for each” activity take a while to find my “if”.
I also tried @prasath17’s solution, but it didn’t work. Because I’m in Brazil, the DateTime format that windows uses is “dd/MM/yyyy”, so I couldn’t handle this in “Where”.
Do you have any idea how I could make this “for each” search more efficient or faster? Or some other alternative?
If not, I’ll need to use the first option even if it takes a while, it’s life haha