G
G
galsik2021-12-21 12:29:56
cmd/bat
galsik, 2021-12-21 12:29:56

Creating many folders in Windows?

Good day, there is such a code

chcp 1251
set papka=1
:1
set /A papka=papka+1
md 1 %papka%
if not %papka%==20 goto 1
del virus.bat


Here, in principle, it will clearly create 20 folders from 1 to 20, but I need to create 1200 folders, and so that the name would be 0001, 0002, 0003, and so on, what should I change here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2021-12-21
@galsik

In batch files, all variables are strings!
set /a for arithmetic converts strings to numbers, does the operations, and stores the string in the result.
Therefore, padding with zeros is simple: we add the maximum required number of zeros to the number, then remove the excess using the substring extraction operation.
To extract substrings read:
set /?

D
Drno, 2021-12-21
@Drno

Assumption -
set papka=0001
:0001
if not %papka%==1200 goto 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question