Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. private string GetNextFileName(string fileName)
  2. {
  3. int index = 1;
  4.  
  5. string nextName = $"{fileName}_{index}.png";
  6.  
  7. while (File.Exists(nextName))
  8. {
  9. nextName = $"{fileName}_{++index}.png";
  10. }
  11.  
  12. return nextName;
  13. }
  14.  
  15. private string GetNextFileName(string fileName)
  16. {
  17. int i = 1;
  18. string nextName = $"{fileName}_{i}.png";
  19.  
  20. for (; i < 100; ++i)
  21. {
  22. if (!File.Exists(nextName))
  23. {
  24. return nextName;
  25. }
  26. nextName = $"{fileName}_{i}.png";
  27. }
  28.  
  29. throw new ApplicationException("Unable to get free filename");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement