简体   繁体   中英

Create 5000 directories with VB.NET

I want to create 5000 directories with the name of the directory being the counter.

Below is my code I want to use but this only create 1 directory for me, why is that?

 Dim Counter As Integer

 Counter = 1

 Do Until Counter = 5000

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

 Loop

        Counter += 1

VB.NET or C# will do, I just want to run this once.

Move counter+=1 inside of the do loop. It probably creates the first directory but because counter never is incremented inside the loop it probably just overwrites itself.

Change to this:

Do Until Counter = 5000

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

Don't use do while with integer, for integer and double types better use function For :

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

PS in your case you need to move counter+=1 before loop statement.

You should really use a For loop for this:

For counter as Integer = 1 To 5000
    FolderPath = "C:/pics/" + counter.ToString() + "/"
    Directory.CreateDirectory(FolderPath)
End For

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM