Reputation: 3
As you may know, md -p can create a tree folder like: mkdir -p
but how to create a "n" deep folder by script such as bat or any other?
Directory tree sample: - C:\ -- 001 --- 002 ---- 003 .............. ----- n
Thanks anyway Rover
Upvotes: 0
Views: 2712
Reputation: 67216
If Command Extensions are enabled (the default) then MD
command will create all intermediate directories in the given path if they don't exists, so you just need to enter something like this:
md C:\001\002\003
Upvotes: 0
Reputation: 70923
( for /l %a in (1 1 10) do md %a & cd %a ) & cd "%cd%"
To be used from command line. To use it inside a batch file, percent signs need to be escaped, replacing %a
with %%a
For a padded version you can use
cmd /v /c "for /l %a in (1001 1 1005) do (set "x=%a" & md !x:~-3! & cd !x:~-3!)"
Upvotes: 1
Reputation: 6032
This script will create 999 folders inside each other (from 001 to 999):
@ECHO OFF
FOR /L %%i IN (1,1,999) DO (
IF %%i LSS 10 (
MD 00%%i
CD 00%%i
) ELSE (
IF %%i LSS 100 (
MD 0%%i
CD 0%%i
) ELSE (
MD %%i
CD %%i
)
)
)
PAUSE
Upvotes: 1