Lynx
(Lnx)
1
Good evening friends, a question please
I need to find the file with last date and containing (TR):
JVL Report - Week 10, 04.03.2024 (TR).xlsb
JVL Report - Week 10, 06.03.2024 (TR).xlsb
JVL Report - Week 10, 04.03.2024.xlsb
JVL Report - Week 10, 06.03.2024.xlsb
I have been trying with :
“Directory.GetFiles(path_file, ).Where(Function(w)(Path.GetFileNameWithoutExtension(w).ToLower.Contains(“TR”))).ToArray()”
But something is not working for me
Thank you very much in advance
lrtetala
(Lakshman Reddy)
2
Hi @Lynx
Try this
latestFile = Directory.GetFiles(path_file).Where(Function(file) Path.GetFileNameWithoutExtension(file).ToLower.Contains("(tr)")) _
.OrderByDescending(Function(file) DateTime.ParseExact(file.Substring(file.IndexOf(",") + 2, 10), "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture)) _
.FirstOrDefault()
Regards,
1 Like
Parvathy
(PS Parvathy)
3
Hi @Lynx
Try this:
latestFile = Directory.GetFiles(path_file).Where(Function(w) Path.GetFileNameWithoutExtension(w).ToLower.Contains("(tr)")).OrderByDescending(Function(f) DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(f), "\d{2}\.\d{2}\.\d{4}").Value, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture)).FirstOrDefault()
Hope it helps!!
Parvathy
(PS Parvathy)
4
Hi @Lynx
Input:
latestFile = Directory.GetFiles(path_file).Where(Function(w) Path.GetFileNameWithoutExtension(w).ToLower.Contains("(tr)")).OrderByDescending(Function(f) DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(f), "\d{2}\.\d{2}\.\d{4}").Value, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture)).FirstOrDefault()
Output:
Hope it helps!!
1 Like
Lynx
(Lnx)
5
Thank you so much Parvathy!
1 Like
Lynx
(Lnx)
7
It works perfectly, thanks a lot!
1 Like
system
(system)
Closed
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.