K
K
Kerson2021-01-04 14:59:22
cmd/bat
Kerson, 2021-01-04 14:59:22

Creating folders for each day with .bat?

Sorry, new to .bat. There was a need to create 30 folders with the name "XX.YY", where X is the date, Y is the month. In this case, the first folder is the first day of the month (01.01), the second folder is the next day (01.02). Also in each of these folders there should be 2 more folders: "wb" and "zaliv". I do not quite understand how to implement this, I hope for your help.

I would be extremely grateful for your dedicated time to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2021-01-04
@res2001

Simplified, you can do this:

@echo off
for /l %%a in (1,1,12) do for /l %%b in (1,1,31) do ( md %%a.%%b\wb 2>nul & md %%a.%%b\zaliv 2>nul)

But here it is assumed that each month has 31 days, and also does not add a non-significant 0 to the left to expand the month / day number to 2 characters.
By simple, you can expand to two characters using not for /l, but the usual one. Of course, you can write a function that expands the string to a given length with the desired character, but too lazy to mess around. You can google for "cmd padding string", on the gray forum and ru-board there are sensible branches on batch files. You can set the exact number of days in a month using a predefined list of days for each month, something like this:
for %%a in (01 02 03 04 05 ...) do
setlocal enabledelayedexpansion
set "mday1=01 02 03 04 05 ..." :: в mday1 - 1 - это номер месяца (январь)
set "mday2=01 02 03 04 05 ..."
:: и так далее до mday12
...
for %%b in (!mday%%a!) do ...

If you don’t bother with expanding numbers to two characters, then in mdayN you can simply set the maximum number of the day and use it infor /l %%b in (1,1,!mday%%a!) do

C
ComodoHacker, 2021-01-04
@ComodoHacker

@echo off
setlocal enabledelayedexpansion
for /l %%I in (1,1,30) do (
  set S=0%%I
  set S=!S:~-2!.01
  mkdir !S!\wb
  mkdir !S!\zaliv
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question