GOTO not working as it should
Posted: 28 Mar 2009 11:09
Hi,
Have created a script to backup files based on user input. Pretty simple but i am having a problem getting the GOTO functions working..namely the ones below
GOTO SHOWDOCS
GOTO SHOWARCH
The script directly takes me back to the menu once the prompt checks if i want to see the backed up files. Need help desparately. Bear in mind, I am a newbie to DOS programming.
SCRIPT BELOW:
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Echo .
Echo Ensure that your drive has been connected and is visible under Windows Explorer.
Echo *****************************************************************************
Echo * *
Echo * Only Proceed if drive is the USB drive is visible *
Echo * *
Echo *****************************************************************************
Echo .
Echo .
FOR /F "tokens=1,2,3 Delims=/" %%A in ('Date /T') do (set foldername=%%A-%%B-%%C)
set foldername=%foldername: =%
Echo "%foldername%"
pause
:MENU
Echo What do you want to backup.
Echo Select your task.
Echo .
cls
Echo [1] Backup My Documents.
Echo [2] Backup Archives.
Echo [3] Backup My Documents and Archives.
Echo [4] Exit.
set /P M=Select your option [1,2,3,4]:
IF %M%==1 GOTO MYDOCS
IF %M%==2 GOTO MYARCH
IF %M%==3 GOTO BOTH
IF %M%==4 GOTO EOF
:MYDOCS
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\My_Docs
xcopy "%userprofile%\My documents\*.*" "%drvltr%:\backup\%username%\%foldername%\My_Docs\" /Y /G /H /O /E
Echo .
Echo .
ECHO COMPLETE.........................................
ECHO .
ECHO .
set /P G=Do you wish to see the backed up files[Y/N]:
IF %G%==Y GOTO SHOWDOCS
IF %G%==N GOTO EOF
GOTO MENU
:MYARCH
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\Archives
xcopy "%userprofile%\Local settings\Application Data\Microsoft\Outlook\*.pst" "%drvltr%:\backup\%username%\%foldername%\Archives\" /Y /G /H /O /E
Echo .
Echo .
ECHO COMPLETE.........................................
Echo .
Echo .
set /P F=Do you wish to see the backed up files[Y/N]:
IF %F%=="Y" GOTO SHOWARCH
IF %F%=="N" GOTO EOF
Goto MENU
:BOTH
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\My_Docs
Mkdir %drvltr%:\backup\%username%\%foldername%\Archives
xcopy "%userprofile%\My documents\*.*" "%drvltr%:\backup\%username%\%foldername%\My_Docs\" /Y /G /H /O /E
xcopy "%userprofile%\Local settings\Application Data\Microsoft\Outlook\*.pst" "%drvltr%:\backup\%username%\%foldername%\Archives\" /Y /G /H /O /E
GOTO MENU
:SHOWARCH
explorer "%drvltr%:\backup\%username%\%foldername%\Archives\"
GOTO Menu
:SHOWDOCS
explorer "%drvltr%:\backup\%username%\%foldername%\My_Docs\"
goto MENU
:EOF
cls
Have created a script to backup files based on user input. Pretty simple but i am having a problem getting the GOTO functions working..namely the ones below
GOTO SHOWDOCS
GOTO SHOWARCH
The script directly takes me back to the menu once the prompt checks if i want to see the backed up files. Need help desparately. Bear in mind, I am a newbie to DOS programming.
SCRIPT BELOW:
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Echo .
Echo Ensure that your drive has been connected and is visible under Windows Explorer.
Echo *****************************************************************************
Echo * *
Echo * Only Proceed if drive is the USB drive is visible *
Echo * *
Echo *****************************************************************************
Echo .
Echo .
FOR /F "tokens=1,2,3 Delims=/" %%A in ('Date /T') do (set foldername=%%A-%%B-%%C)
set foldername=%foldername: =%
Echo "%foldername%"
pause
:MENU
Echo What do you want to backup.
Echo Select your task.
Echo .
cls
Echo [1] Backup My Documents.
Echo [2] Backup Archives.
Echo [3] Backup My Documents and Archives.
Echo [4] Exit.
set /P M=Select your option [1,2,3,4]:
IF %M%==1 GOTO MYDOCS
IF %M%==2 GOTO MYARCH
IF %M%==3 GOTO BOTH
IF %M%==4 GOTO EOF
:MYDOCS
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\My_Docs
xcopy "%userprofile%\My documents\*.*" "%drvltr%:\backup\%username%\%foldername%\My_Docs\" /Y /G /H /O /E
Echo .
Echo .
ECHO COMPLETE.........................................
ECHO .
ECHO .
set /P G=Do you wish to see the backed up files[Y/N]:
IF %G%==Y GOTO SHOWDOCS
IF %G%==N GOTO EOF
GOTO MENU
:MYARCH
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\Archives
xcopy "%userprofile%\Local settings\Application Data\Microsoft\Outlook\*.pst" "%drvltr%:\backup\%username%\%foldername%\Archives\" /Y /G /H /O /E
Echo .
Echo .
ECHO COMPLETE.........................................
Echo .
Echo .
set /P F=Do you wish to see the backed up files[Y/N]:
IF %F%=="Y" GOTO SHOWARCH
IF %F%=="N" GOTO EOF
Goto MENU
:BOTH
SET /P DRVLTR=ENTER THE DRIVE LETTER FOR THE USB DRIVE [Example D]:
Mkdir %drvltr%:\backup\%username%\%foldername%\My_Docs
Mkdir %drvltr%:\backup\%username%\%foldername%\Archives
xcopy "%userprofile%\My documents\*.*" "%drvltr%:\backup\%username%\%foldername%\My_Docs\" /Y /G /H /O /E
xcopy "%userprofile%\Local settings\Application Data\Microsoft\Outlook\*.pst" "%drvltr%:\backup\%username%\%foldername%\Archives\" /Y /G /H /O /E
GOTO MENU
:SHOWARCH
explorer "%drvltr%:\backup\%username%\%foldername%\Archives\"
GOTO Menu
:SHOWDOCS
explorer "%drvltr%:\backup\%username%\%foldername%\My_Docs\"
goto MENU
:EOF
cls