.BAT script only running 1st command.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
glennm
Posts: 1
Joined: 16 Jun 2018 06:27

.BAT script only running 1st command.

#1 Post by glennm » 16 Jun 2018 06:37

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"

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: .BAT script only running 1st command.

#2 Post by Squashman » 16 Jun 2018 09:16

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.

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: .BAT script only running 1st command.

#3 Post by pieh-ejdsch » 16 Jun 2018 09:36

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

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: .BAT script only running 1st command.

#4 Post by tweacle » 16 Jun 2018 09:40

Aaaaahhhh See what you mean now

Thanks

Post Reply