Does anyone know how I can create a batch file which creates folders in a certain directory with the incremental name of "Problem 1", "Problem 2", ...
Asked
Active
Viewed 8,110 times
1 Answers
9
Sure, like so (if it's in a batch file):
for /l %%x in (1, 1, 100) do mkdir "Problem %%x"
Or just simply on the command line:
for /l %x in (1, 1, 100) do mkdir "Problem %x"
See here: Batch script loop
If you want to do it in Powershell it's a simple one liner like so:
for($i = 1; $i -lt 100; $i++) { md "Problem $i" }
or
1..100 | ForEach-Object{md "Problem $_"}
-
1Thanks, I used the batch file and ran it. Worked a treat! – Khalid Jan 16 '15 at 19:56
-
1Glad to help, added Powershell to the answer as well. – cjones26 Jan 16 '15 at 19:56
-
If I wanted to start it at say Problem 101 onwards, how would I do this? – Khalid Jan 16 '15 at 19:58
-
1In Powershell you'd change the "$i = 1" to 101 (and the 100 to your end value). On the batch script, change the "in (1, 1, 100)" to "in (x, 1, y)" where x is your start value and y is your end value (inclusive). – cjones26 Jan 16 '15 at 20:00