Page 1 of 1

.BAT script only running 1st command.

Posted: 16 Jun 2018 06:37
by glennm
Hi

I got the batch script below that asks me 3 questions. It comes up with the 1st question OK but when I push Y or N thats it stopsand goes no further.

What am I doing wrong? Script below.

Code: Select all

@echo off 
setlocal EnableDelayedExpansion
 
rem Define folder paths
set BaseDir=C:\DOWNLOADS
set DestDir1=C:\DAVID DOWNLOADS
set DestDir2=C:\JAMES DOWNLOADS
set DestDir3=C:\DISK BURNING FOLDER

 
rem Quit if no files in download area to process
set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
    echo No new files to process, quitting.
    exit /b
)
 
rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"
 
rem If none entered, exit script
if "%RefNum%" EQU "" exit /b
 
rem Make a subfolder for the reference number
md "%BaseDir%\%RefNum%"
 
rem Move all files to new subfolder
move "%BaseDir%\*.*" "%BaseDir%\%RefNum%"
 
rem Ask if DAVID download to determine where to move the new folder
choice /C YN /M "IS THIS A DAVID DOWNLOAD (Y/N)?"
if !ERRORLEVEL! EQU 1 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"
echo msgbox "DO NOT FORGET TO GO INTO DAVID DOWNLOADS FOLDER” 
 > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"
) else (
  choice /C YN /M "IS THIS A JAMES DOWNLOAD(Y/N)?"
  if !ERRORLEVEL! EQU 1 (
    move "%BaseDir%\%RefNum%" "%DestDir2%"
echo msgbox "DO NOT FORGET TO GO INTO JAMES DOWNLOADS  AND PASSWORD PROTECT FOLDER!!!!" > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"

) else (
   choice /C YN /M "IS THIS A BURN TO DISK DOWNLOAD? (Y/N)?"
   if !ERRORLEVEL! EQU 1 (
  move "%BaseDir%\%RefNum%" "%DestDir3%"

echo msgbox "NOW GO INTO DVD DRIVE AND BURN TO DISK. " > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"

 
rem Remove ALL files from base download folder
del /s /q "%BaseDir%\*.*"
 
rem Remove any remaining subfolders too
for /d %%A in ("%BaseDir%\*.*") do rd /s /q "%%~A"

Re: .BAT script only running 1st command.

Posted: 16 Jun 2018 09:16
by Squashman
If the for command does not find any files to process, it will not execute the set command to change the variable to N. You need to reverse your logic.

Re: .BAT script only running 1st command.

Posted: 16 Jun 2018 09:36
by pieh-ejdsch

Code: Select all

if NOT ERRORLEVEL 2 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"
  > "%temp%\popup.vbs" echo msgbox "DO NOT FORGET TO GO INTO DAVID DOWNLOADS FOLDER” 
  wscript.exe "%temp%\popup.vbs"
) else (
  choice /C YN /M "IS THIS A JAMES DOWNLOAD(Y/N)?"
  if NOT ERRORLEVEL 2 (
    move "%BaseDir%\%RefNum%" "%DestDir2%"
    > "%temp%\popup.vbs" echo msgbox "DO NOT FORGET TO GO INTO JAMES DOWNLOADS  AND PASSWORD PROTECT FOLDER!!!!"
    wscript.exe "%temp%\popup.vbs"
  ) else (
    choice /C YN /M "IS THIS A BURN TO DISK DOWNLOAD? (Y/N)?"
    if NOT ERRORLEVEL 2 (
      move "%BaseDir%\%RefNum%" "%DestDir3%"
      > "%temp%\popup.vbs" echo msgbox "NOW GO INTO DVD DRIVE AND BURN TO DISK. "
      wscript.exe "%temp%\popup.vbs"
) ) )
You have no balanced parenthesis and an incomplete Redirect!

You can test your Batch creations with this batch:
checkCMD.cmd MyCreated.Bat

Phil

Re: .BAT script only running 1st command.

Posted: 16 Jun 2018 09:40
by tweacle
Aaaaahhhh See what you mean now

Thanks