Help needed for creating Folder structure

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
amitananddey
Posts: 14
Joined: 16 Jan 2012 04:56

Help needed for creating Folder structure

#1 Post by amitananddey » 16 Jan 2012 05:20

I guess this might seem pretty noobish to ask.I am a completely new to programming.I need help for a little .bat script which I made.
Colors>red
>blue
>green
>orange
>and more
Right now what I do is go to every folder and run the script.
I want a script which will create folder structure inside all the folders.
Right now I am using this

if not exist "1\" (
md 1
md 1\a
md 1\b
md 1\c

)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help needed for creating Folder structure

#2 Post by Squashman » 16 Jan 2012 07:25

Are you saying you have this folder structure

Code: Select all

E:\>tree colors
Folder PATH listing for volume Big Drive
Volume serial number is D23A-41A4
E:\COLORS
├───blue
├───green
├───oragne
└───red

And you want a script to make a series of sub folders named 1\a 1\b and 1\c inside each of them to look like this?

Code: Select all

E:\>tree colors
Folder PATH listing for volume Big Drive
Volume serial number is D23A-41A4
E:\COLORS
├───blue
│   └───1
│       ├───a
│       ├───b
│       └───c
├───green
│   └───1
│       ├───a
│       ├───b
│       └───c
├───oragne
│   └───1
│       ├───a
│       ├───b
│       └───c
└───red
    └───1
        ├───a
        ├───b
        └───c

amitananddey
Posts: 14
Joined: 16 Jan 2012 04:56

Re: Help needed for creating Folder structure

#3 Post by amitananddey » 16 Jan 2012 11:41

@Squashman
yes exactly...
**sorry for my poor explanation..

aGerman
Expert
Posts: 4710
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help needed for creating Folder structure

#4 Post by aGerman » 16 Jan 2012 11:56

Code: Select all

for /d %%i in ("E:\COLORS\*") do (
  md "%%i\1\a"
  md "%%i\1\b"
  md "%%i\1\c"
)


It doesn't matter if one of the folders already exists. It will not be overwritten, all you get is an error message in this case.

Regards
aGerman

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Help needed for creating Folder structure

#5 Post by !k » 16 Jan 2012 13:31

aGerman wrote: md "%%i\1\a"
md "%%i\1\b"
md "%%i\1\c"


Code: Select all

  md "%%i\1\a" "%%i\1\b" "%%i\1\c" 2>nul

aGerman
Expert
Posts: 4710
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help needed for creating Folder structure

#6 Post by aGerman » 16 Jan 2012 13:40

:o
That's undocumented. I wasn't aware this could work. Awesome :!:

Regards
aGerman

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help needed for creating Folder structure

#7 Post by Ed Dyreen » 16 Jan 2012 16:03

'
Never seen that before :D !k++

amitananddey
Posts: 14
Joined: 16 Jan 2012 04:56

Re: Help needed for creating Folder structure

#8 Post by amitananddey » 16 Jan 2012 22:06

Thanks a lot !k and aGerman..

amitananddey
Posts: 14
Joined: 16 Jan 2012 04:56

Re: Help needed for creating Folder structure

#9 Post by amitananddey » 16 Jan 2012 23:39

The following is the folder structure I need.
E:\COLORS
├───scriptfile
│ createfolders.bat
├───green
│ └───1
│ ├───a
│ ├───b
│ └───c
├───oragne
│ └───1
│ ├───a
│ ├───b
│ └───c

Since I wanted the batch file to create folders in current directory.I modified it to this

SET "CDIR=%~dp0"
for /d %%i in ("%CDIR%\..\*") do (
md "%%i\1\a"
md "%%i\1\b"
md "%%i\1\c"
)
The problem is when createfolders.bat is executed , it creates the folder structure in all the folders including its parent folder.
Is it possible to exclude its parent folder/a particular folder ; and to create folder structure in the rest

Post Reply