// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; namespace E { public class Program { public static void Main(string[] args) { string fnm = @"C:\z.cs"; string first = Path.Combine(Path.GetDirectoryName(fnm), Path.GetFileNameWithoutExtension(fnm)); string last = Path.GetExtension(fnm); string tmpfnm = fnm; int n = 0; while (File.Exists(tmpfnm)) { n++; tmpfnm = first + "_" + n + last; } Console.WriteLine(tmpfnm); } } }