Warehouse.Utils.AssureUniqueFilename C# (CSharp) Method

AssureUniqueFilename() public static method

Assure the a file is unique in a folder by assiging a counting number at the end of the file.
public static AssureUniqueFilename ( string folder, string fileName, string &newFile ) : void
folder string
fileName string
newFile string
return void
        public static void AssureUniqueFilename(string folder, string fileName, out string newFile) {
            int cnt = 1;
            newFile = Path.Combine(folder, fileName);
            while (File.Exists(newFile)) {
                string fName = Path.GetFileNameWithoutExtension(fileName);
                string ext = Path.GetExtension(fileName);
                string newFileName = fName + " (" + cnt++ + ")";
                if (!string.IsNullOrEmpty(ext)) {
                    newFileName = newFileName + ext;
                }
                newFile = Path.Combine(folder, newFileName);
            }
        }