c# - Get Date From Filename Using ParseExact -
i trying find file has highest date in single directory. problem dates attached filenames. using following code try pull max date running trouble parseexact.
//gather of files in local directory var files = directory.enumeratefiles(r.getleadlocalfile()); returndatetime = files.max(f => datetime.parseexact(f, "mmddyyxxxx.csv", cultureinfo.invariantculture));
i continue following error:
string not recognized valid datetime.
i can tell value of file path being passed in because value of 'f' below:
\\\\vamarnas02\\users\\meggleston\\user files\\leads\\110716enh9.csv
the value of enh9 can change depending on file.
how can datetime filename?
you need split out date text before parsing. following code snippet should help.
assume variable f filename.
datetime.parseexact(f.substring( f.lastindexof("\\") + 1, 6), "mmddyy", cultureinfo.invariantculture);
Comments
Post a Comment