Messages - ghendric [ switch to compact view ]

Pages: [1]
1
This version works pretty good too.
Code: C# [Select]
  1. private string GetNextFileName(string fileName) {
  2.             string extension = Path.GetExtension(fileName);
  3.             string pathName = Path.GetDirectoryName(fileName);
  4.             string fileNameOnly = Path.Combine(pathName, Path.GetFileNameWithoutExtension(fileName));
  5.             int i = 0;
  6.             // If the file exists, keep trying until it doesn't
  7.             while (File.Exists(fileName)) {
  8.                 i += 1;
  9.                 fileName = string.Format("{0}({1}){2}", fileNameOnly, i, extension);
  10.             }
  11.             return fileName;
  12.         }

Pages: [1]
Go to full version