Hi,
How to construct filename for the this(abc_{yyMMdd}_xyz_{HHmm}.txt) format, The function should return filename like this abc_140822_xyz_1446.txt.
Please post solution for this post.
Thanks in Advance
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 22, 2014, 6:58 AM EDT
When I tried it just now (UK time) the output was:
KalaiRank #8,005 · 230 reputationPosted Aug 22, 2014, 3:41 AM EDT
public string GenerateFileName()
{
string yy = DateTime.Now.Year.ToString();
yy = yy.Substring(yy.Length - 2);
string mm = DateTime.Now.Month.ToString().Length == 1 ? "0" + DateTime.Now.Month.ToString() : DateTime.Now.Month.ToString();
string dd = DateTime.Now.Day.ToString().Length == 1 ? "0" + DateTime.Now.Day.ToString() : DateTime.Now.Day.ToString();
string filename = "abc_" + yy + mm + dd + "_xyz_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".txt";
return filename;
}
Rajkumar R175 reputationPosted Aug 22, 2014, 3:52 AM EDT
I will pass this "abc_{yyMMdd}_xyz_{HHmm}" as an input parameter to the function. The function should return appropriate filename. Sometime the input parameter may be like this "abc_{yyMMdd_HHmm}." So the function should handle all the cases,
Thanks in Advance.
KalaiRank #8,005 · 230 reputationPosted Aug 22, 2014, 5:06 AM EDT
http://www.codeproject.com/Questions/322056/search-files-in-directory-Csharp