数が増えるバックアップ フォルダを作成する必要があります。ただし、番号付けのギャップが存在する場合はスキップし、次のフォルダー名を最大番号のフォルダーよりも 1 つ大きくする必要があります。たとえば、私が持っている場合:
c:\バックアップ\data.1 c:\バックアップ\data.2 c:\バックアップ\data.4 c:\バックアップ\data.5
次のフォルダが必要です
c:\バックアップ\data.6
以下のコードは機能しますが、ひどくぎこちなく感じます。これを行い、.NET 2.0 のままにするより良い方法はありますか?
    static void Main(string[] args)
    {
        string backupPath = @"C:\Backup\";
        string[] folders = Directory.GetDirectories(backupPath);
        int count = folders.Length;
        List<int> endsWith = new List<int>();
        if (count == 0)
        {
            Directory.CreateDirectory(@"C:\Backup\Data.1");
        }
        else
        {
            foreach (var item in folders)
            {
                //int lastPartOfFolderName;
                int lastDotPosition = item.LastIndexOf('.');
                try
                {
                    int lastPartOfFolderName = Convert.ToInt16(item.Substring(lastDotPosition + 1));
                    endsWith.Add(lastPartOfFolderName);
                }
                catch (Exception)
                {
                   // Just ignore any non numeric folder endings
                }
            }
        }
        endsWith.Sort();
        int nextFolderNumber = endsWith[endsWith.Count - 1];
        nextFolderNumber++;
        Directory.CreateDirectory(@"C:\Backup\Data." + nextFolderNumber.ToString());
    }
ありがとう