mardi 4 août 2015

batch file exits before input criteria is satisfied

I've created a batch file to right click in explorer and ask the user for a folder name. If the folder already exists, I want to keep asking the user until one that does not exist is entered. The file exits after two runs through if the folder already exists and I can't figure out why this happens. It looks to me like it should continually call main until it gets a folder name that doesn't exist. See code below

set verbose=NO
@echo off

set mydir = %cd%
cd %mydir%
cls

call:main
echo returned from main
pause
goto:eof

:main
set /p job=Enter Job Name:
echo %job%
call:check
echo returned from check
if choice==1 call:main
echo returned from main
pause
if choice==2 call:createDirectory

:check
if exist %job% (echo Folder already exists set choice=1) else (set choice=2)
echo %choice%



:createDirectory
md "%job%"

md "%job%"\1.Development
md "%job%"\1.Development\1.Budgets
md "%job%"\1.Development\2.Manufacturers

md "%job%"\"2.Plans and Specs"
md "%job%"\"2.Plans and Specs"\1.Plans
md "%job%"\"2.Plans and Specs"\2.Specs

md "%job%"\3.Pricing
md "%job%"\3.Pricing\1.Quotes
md "%job%"\3.Pricing\2.Worksheets

md "%job%"\4.Sumbittals
md "%job%"\4.Sumbittals\"1.Submittal Reviews"

md "%job%"\5.Orders
md "%job%"\5.Orders\"1.Order Summaries"
md "%job%"\5.Orders\"2.Confirmation Pages"

md "%job%"\6.Closeout
md "%job%"\6.Closeout\"1.O&M Manuals"
md "%job%"\6.Closeout\2.Warranty

Aucun commentaire:

Enregistrer un commentaire