1

I have made a very basic batch file with the code shown below.
(The actual structure is much more complex - I've shown only a simple portion for the sake of this question)

    mkdir Client
    mkdir Comment
    mkdir Work
    cd Work
    mkdir Native
    mkdir PDF
    mkdir Review
    cd Review
    mkdir QC
    mkdir SIS
    cd SIS
    mkdir LEAD
    mkdir FSM 

Which creates a tree structure shown below.

Output of TREE command

The problem is I have to copy the batch file to that respective location before I execute it to get the required structure.
What piece of code should I add, so that it will ask the user where this structure has to be created? (The reason why I don't want this to be copied to every other location, because in case, if there are any changes to be done in the structure, I will have to hunt down all these files and update them. It is better if it is in one location which makes updates easier)

Edit

My sample location or root looks like this with spaces and hyphens
\\Bh.me.ykgw.net\yeu-eng1\ENG\Current Projects\POFR02-NORTH RUMAILA INLET BOOSER COMPRESSION PROJECT (NR-IBCS)\C_Technical\C4_Design_Deliverables\C4.1.12.Bill of Materials\Work\IPS & FGS\08A\Client

  • Wondering how to make my script (code) above color coded!... Last time some one edited my VBA and gave it the color code it needs... – Prasanna Sep 9 '15 at 6:27
  • 2
    Note you can simplify your batch file as "MD creates any intermediate directories in the path, if needed". So you can get rid of the the CD commands (they will not be needed) and use commands like md work\Review\SIS\FSM which will create all the required directories in one command. – DavidPostill Sep 9 '15 at 7:39
1

You need to get root directory from user input?

set /p rd="Enter root directory: "
cd %rd%
mkdir Client
mkdir Comment
mkdir Work
cd Work
mkdir Native
mkdir PDF
mkdir Review
cd Review
mkdir QC
mkdir SIS
cd SIS
mkdir LEAD
mkdir FSM 
1

In order to ask the user for the location in which this directory structure will be recreated you'll need to add the following lines at the very beginning of your script.

In case you plan to ask the user a directory

SET /P locn="Enter the location : "
cd %locn%

In case you plan to ask the user to enter a drive-letter

SET /P drive="Enter the drive letter"
%drive%:
  • 1
    Please upvote & select my answer if you felt it helped you :) Thank you – Dhiwakar Ravikumar Sep 9 '15 at 6:42
  • My location is something like this \\Bh.me.ykgw.net\yeu-eng1\ENG\Current Projects\POFR02-NORTH RUMAILA INLET BOOSER COMPRESSION PROJECT (NR-IBCS)\C_Technical\C4_Design_Deliverables\C4.1.12.Bill of Materials\Work\IPS & FGS\08A\Client. The command prompt just closes and doesn't do anything – Prasanna Sep 9 '15 at 6:45
  • Try with quotes "\\Bh.me.ykgw.net\yeu-eng1\ENG\Current Projects\POFR02-NORTH RUMAILA INLET BOOSER COMPRESSION PROJECT (NR-IBCS)\C_Technical\C4_Design_Deliverables\C4.1.12.Bill of Materials\Work\IPS & FGS\08A\Client" But I'm not sure, it may be not work with network paths. – strangeman Sep 9 '15 at 6:54
  • It didn't work with the quotes either – Prasanna Sep 9 '15 at 7:55
  • Check if you have write permissions on the share. Then try mapping the share to a network drive and see if this batch script works – Dhiwakar Ravikumar Sep 9 '15 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.