Naveen Gamage
Naveen Gamage

Reputation: 1884

Translating shell script into Windows command shell script (batch)

I have a shell script which makes directories week_01 to week_09 using a for loop and one another directory called week_10. I want to translate this shell script into Windows commands using two lines of code?

Shell Script:

#!/bin/bash
for (( Y=1;Y<=9;Y++))
do
mkdir week_0$Y
done
mkdir week_10

Upvotes: 0

Views: 361

Answers (4)

foxidrive
foxidrive

Reputation: 41234

If that is really your task then this will work, too.

@echo off
for %%a in (01 02 03 04 05 06 07 08 09 10) do Mkdir "week_%%a"

Upvotes: 1

Aacini
Aacini

Reputation: 67216

Another one!

@echo off & setlocal EnableDelayedExpansion
set folder=101
for /L %%i in (1,1,10) do (
   mkdir week_!folder:~-2!
   set /A folder+=1
)

Upvotes: 2

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

for /L makes a count-controlled loop in batch. mkdir remains mkdir.

@echo off
for /L %%y in (1,1,9) do mkdir week_0%%y
mkdir week_10

Upvotes: 2

Endoro
Endoro

Reputation: 37569

try this:

@echo off &setlocal enabledelayedexpansion
for /l %%i in (101,1,110) do (
    set "folder=%%i"
    set "folder=week_!folder:~1!"
    echo mkdir "!folder!"
)

Upvotes: 2

Related Questions