使用VB.NET创建5000个目录

Eti*_*nne 1 c# vb.net directory

我想创建5000个目录,目录的名称是计数器.

下面是我想要使用的代码,但这只为我创建了一个目录,为什么呢?

 Dim Counter As Integer

 Counter = 1

 Do Until Counter = 5000

       FolderPath = "C:/pics/" + Counter.ToString() + "/"
       Directory.CreateDirectory(FolderPath)

 Loop

        Counter += 1
Run Code Online (Sandbox Code Playgroud)

VB.NET或C#会做,我只想运行一次.

Jon*_*onH 6

移动counter+=1do循环内部.它可能会创建第一个目录,但因为计数器永远不会在循环内增加,所以它可能只会覆盖它自己.

改为:

Do Until Counter = 5000

       FolderPath = "C:/pics/" + Counter.ToString() + "/"
       Directory.CreateDirectory(FolderPath)
        Counter += 1
 Loop
Run Code Online (Sandbox Code Playgroud)


Eps*_*neR 5

不要使用do while整数,对于整数和双精度类型更好的使用函数For:

For Counter as Integer = 1 to 5000
   FolderPath = "C:/pics/" + Counter.ToString() + "/"
   Directory.CreateDirectory(FolderPath)
Next
Run Code Online (Sandbox Code Playgroud)

PS在你的情况下你需要counter+=1在loop声明前移动.