Solved

Batch File - Prompt User for Folder Name

Posted on 2010-11-21
14
764 Views
Last Modified: 2012-05-10
I am creating a batch file that create many sub folders. I need the user to have ability to enter in the root folder name. Any ideas?
0
Comment
Question by:ntran80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 

Author Comment

by:ntran80
ID: 34183565
Sorry - I should expand my question.
The user would run my batch file as many time as neccessary to create the folder (with several pre define subfolders) When they click on the batch file, I like have a screen pop up for the user to name the folder.

Thanks in advances
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34183567
set /P root=Which folder to start with? 

Open in new window

should work. You can than refer to it with %root%.
0
 

Author Comment

by:ntran80
ID: 34184512
Can you write up the sample  command line? For example:
- lets say users click on the batch file, it prompts for the folder name, they type in "Tax Years"
- the batch file runs, it creates a folder name "Tax Years" then the following sub folders
2009
2010
etc...

Thank you.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 70

Expert Comment

by:Qlemo
ID: 34184567
Something lie this:
@echo off
set /P "root=Please type in the path where to create all folders in: "
for %%F in (2009 2010 etc) do md %root%\%%F

Open in new window

We do not need to create the root folder, it is automatically created (if cmd.exe command extensions are on, which is the default).
0
 

Author Comment

by:ntran80
ID: 34184726
Actually - all folders will be create where the user run the batch file.
The user will be prompt to type in the folder name, not the path. The batch file will create the folder using user's input, then continue to create all sub folders (2009, 2010, etc...)

Thanks  
0
 
LVL 66

Expert Comment

by:johnb6767
ID: 34185316
No disrepesct intended, but I am not sure I see the purpose of automating this? Seems llike this is actually more complicated than having someone create a folder by hand.....
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34186168
I agree. As long as you do not have a big bunch of folders, or complete trees, the manual method is better.

You are not clear and logical in your demands. If you let them provide a folder name, where should that folder be created? You always need a path to start with, else the batch file will create the folder wherever it sees fit.
0
 

Author Comment

by:ntran80
ID: 34215595
The user will be creating folders on regular basics; I need to have it automated as much as possible.

Sorry – I will attempt to explain it again. Please see attached file.
See the root level named “Client Name A”? Under “Client Name A” there are sub folders with different years; under “year’s folders” there will more sub folders several levels deep.

User clicks on the batch file, let’s say they type in “Client Name B” the batch file would create root level folder name “Client Name B” then all the predefine sub folders. Hope this will help clarify little better.


 
 
Screenshot.pdf
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 34216388
I assume the folders in the years' folders are the same. Then my batch works, slightly modified:
@echo off
set /P "root=Folder to create? "
for %%F in (2009 2010 etc) do ^
for %%G in (
   one\oneone
   two\twoone two\twotwo
   three
   four\fourone\next
   five
) do ^
md "C:\%root%\Year %%F\%%G"

Open in new window

That again assumes you have not too much of folders to create, and no repetitive structure under the subfolders of years.
0
 

Author Comment

by:ntran80
ID: 34332512
Thanks
0
 

Author Comment

by:ntran80
ID: 34468771
Qlemo:

Thanks again for adviced. The batch file worked great!
Here is mine final version (well sort of)

@echo off
set /P "root=Folder to create? "
for %%F in (2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2019 2020 PERM Planning_Advisory) do ^
for %%G in (
   Accounting_Services
   Audit
   Compilations
   Review
   Tax
   
) do ^
md "L:\%root%\%%F\%%G\"

Now I was asked to make a minor change to the batch file.
Under PERM and Planning_Advisory, is there anyway for the batch file NOT to create these subfolders
 Accounting_Services
 Audit
 Compilations
 Review
 Tax

Thanks in advances.

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34468886
The obvious answer is: Just remove them from the first FOR. I assume you only want to create that two folders, no subfolders in them, then add another command at the end of the batch:
for %%F in (PERM Planning_Advisory) do md "L:\%root%\%%F"

Open in new window

or put the corresponding mkdir commands there:
md "L:\%root%\PERM"
md "L:\%root%\Planning_Advisory"

Open in new window

whatever you like more. If you put the command(s) at the end of the batch, they are NOT part of the for %%F loop (only the first MD is, because its line is prefixed with a caret, which says "continue on next line").

So, put together and using one of the above options:
@echo off
set /P "root=Folder to create? "
for %%F in (2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2019 2020) do ^
for %%G in (
   Accounting_Services
   Audit
   Compilations
   Review
   Tax
   
) do ^
md "L:\%root%\%%F\%%G\"

md "L:\%root%\PERM"
md "L:\%root%\Planning_Advisory"

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 34468891
Next improvement, since your years are consecutive:

@echo off
set /P "root=Folder to create? "
for /L %%F in (2006, 1, 2020) do ^
for %%G in (
   Accounting_Services
   Audit
   Compilations
   Review
   Tax
   
) do ^
md "L:\%root%\%%F\%%G\"

md "L:\%root%\PERM"
md "L:\%root%\Planning_Advisory"

Open in new window

0
 

Author Comment

by:ntran80
ID: 34468954
Qlemo:

Ahh...
You made this look easy.
Thank you so much for all your help!!!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question