Example #1
0
        public static string MakeFileNameUnique(string name)
        {
            string path                = System.IO.Path.GetDirectoryName(name);
            string file_name           = System.IO.Path.GetFileName(name);
            string file_name_wo_suffix = System.IO.Path.GetFileNameWithoutExtension(file_name);
            string ext   = System.IO.Path.GetExtension(file_name);
            bool   found = GeneratedFiles.Any(s => string.Equals(s, name, System.StringComparison.OrdinalIgnoreCase));

            if (found)
            {
                int counter = 1;
                for (;;)
                {
                    string alt = path + System.IO.Path.DirectorySeparatorChar + file_name_wo_suffix + "-" + counter++ + ext;
                    if (!GeneratedFiles.Any(s => string.Equals(s, alt, System.StringComparison.OrdinalIgnoreCase)))
                    {
                        return(alt);
                    }
                    counter++;
                }
            }
            return(name);
        }