Я пробовал, как сделать папку с автоматическим увеличением, но есть проблема при нумерации, кто-нибудь знает, где проблема?Как сделать папку с автоматическим увеличением?
public void NewFolder()
{
try
{
string FolderName = Path.Combine(txtOutputFileEn.Text, txtNamaFile.Text);
tempFolder = FolderName;
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
}
else if (Directory.Exists(tempFolder))
{
tempFolder = tempFolder + ("001");
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
}
else if (Directory.Exists(tempFolder))
{
int x = 1;
for (x = 0; x < 50; x++)
{
string angkaString = tempFolder.Substring(tempFolder.Length - 3);
int angka = Convert.ToInt32(angkaString) + x;
string angka00 = "00" + angka.ToString();
tempFolder = FolderName + angka00.Substring(angka00.Length - 3);
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
return;
}
}
}
}
MessageBox.Show(tempFolder);
}
catch (IOException ex)
{
MessageBox.Show(this, ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Здесь выводится папка имя = folder001, folder002, folder004, folder007, folder11, folder16, folder22.
Я хочу, чтобы сделать имя = folder001, folder002, folder003, folder004 .. следующий
ваш probl em: 'int angka = Convert.ToInt32 (angkaString) + x;' означает '1 + 1 = 2; 2 + 2 = 4; 4 + 3 = 7; 7 + 4 = 11' ... и т. Д. – Bolu
@Bolu Думаю, мне нужно восстановить значение x, добавив x = 1, где код должен меняться? – sloqye
use 'int angka = Convert.ToInt32 (angkaString) + 1;' См. Ответ Shahrooz Jefri ㇱ – Bolu