We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

batch file/command  to create a folder in multiple folders

wiafelice
wiafelice asked
on
Medium Priority
461 Views
Last Modified: 2012-06-21
I need to create a folder inside of  2600 folders.  The folder that needs to be created will be the same name. Probably the year- \2006.  The 2600 folders are at the same lvl so they all have different names.

\clients\abc\2006
---------\bcd\2006
----------\cdf\2006
----------\def\2006

I was hoping there was an easy way to copy or move a folder into multiple folders but it does not seem to work when I copy the folder to clipboard, then ctrl-a to select all the folders under clients and then paste.
Comment
Watch Question

Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
Use this ONE command on the command line, NOT in a batch file (as is, it won't work in a batch file).

FOR /F "Tokens=1" %a in ('DIR /ad /b') Do MD %a\2006
Technology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
TEST FIRST by using this:

FOR /F "Tokens=1" %a in ('DIR /ad /b') Do @ECHO MD %a\2006

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Perfect answer.  Is there any documentation on where you got that syntax from?  I would love to mess around with those paramaters.
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
Type FOR /? at a command prompt.

Also, review:
www.robvanderwoude.com - spefically the Batch File section.

Author

Commented:
Thanks for the fast replies btw,

but after working with this on a test folder I found out this does not work with folders that are long filesanmes.  The folders i need to add the \2006 folder to can be any number of words/numbers/spaces.  After looking at the syntax I'm not sure where to add the parameter.  I assume it is part of the tokens parameter.

Any info would be great


Author

Commented:
after more research/testing it looks like it works with replacing the tokens=1 to tokens=*  again I am just testing this on a test folder with no problems.  I will get a solid backup before i try it on our live folder.

Thanks again for the help
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
Yes, * will work - and possibly better if you have any folders with spaces in them (I try to avoid creating folders with spaces and don't always remember to point that out.

Commented:
This Has also Helped me very much. Thank Everyone for all of the input.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.