Automatically increment filename
c#, file, search
Solution
Like @Quintin said, use datetime for filename:
string filename = Path.Combine(
di.FullName,
String.Format("{0}.jpg", DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss")));
bmpScreenShot.Save(filename, ImageFormat.Jpeg);
Problem
Right now I have this code: ``` int number = 0; DirectoryInfo di = new DirectoryInfo(scpath + @"Screenshots\"); if (di.Exists) { } else { di.Create(); } int screenWidth = Screen.GetBounds(new Point(0, 0)).Width; int screenHeight = Screen.GetBounds(new Point(0, 0)).Height; Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight); Graphics gfx = Graphics.FromImage((Image)bmpScreenShot); gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight)); bmpScreenShot.Save(di + "Screenshot_" + number, ImageFormat.Jpeg); ``` Program takes a screenshot (which works) and saves it. What I want to do is to have the program check and see if a screenshot exists ("Screenshot_*") and to create it if it doesn't. If it does, increment file name till it hits a number that hasn't been used at the end of "Screenshot_" Not sure how to go about this given that it's more with files and incrementing. I'm thinking about a for loop but I'm playing with it now.