0

I want to add a number to the end of the directory for example, if the directory was called test, I want the other directory to be made test1 and then test2.

So basically, I want to make a directory which carries on from the previous by putting a number at the end. So it checks which directory was the last one e.g. Test1 and makes Test2

Thanks.

4

1 回答 1

0

这很简单:您从数字开始"test"并附加数字,直到找到一个不存在的名称:

var baseName = "test";
var name = baseName;
int i = 1;
while(Directory.Exists(name))
{
    name = baseName + i;
    ++i;
}

return name;
于 2013-06-06T10:21:49.853 回答