NekoKun.StorageManager.GetNextName C# (CSharp) Method

GetNextName() public static method

public static GetNextName ( string baseDirectory, string format ) : string
baseDirectory string
format string
return string
        public static string GetNextName(string baseDirectory, string format)
        {
            string name;
            int counter = 0;
            do
            {
                counter += 1;
                name = String.Format(format, counter);
            }
            while (System.IO.Directory.Exists(System.IO.Path.Combine(baseDirectory, name)));
            return name;
        }

Usage Example

Example #1
0
 void FillFields()
 {
     this.fieldName.Text     = StorageManager.GetNextName(StorageManager.GetUserDirectory("Projects"), "Project{0}");
     this.fieldLocation.Text = System.IO.Path.Combine(
         StorageManager.GetUserDirectory("Projects"),
         invalidChars.Replace(this.fieldName.Text, "")
         );
 }