Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Quick batch file question

28 Oct 2010   #11

win7
 
 

Hi Liam,

I added a line underneath your timeout that piped the program to a subroutine called net_action wich is at the bottom of the script. Note I have added a pause statement after so that you can see that it does indeed pipe to the subroutine because the batch program would terminate otherwise, as soon as it echo'd the "here" statement. Remove this and add you new segment instead.

@ECHO OFF
ECHO WELCOME TO LIAM'S BACKUP WIZARD
GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
TIMEOUT /T 10
goto next_action

SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
:iTUNES
ECHO YOU HAVE CHOSEN TO BACKUP THE iTUNES MUSIC FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /L /E /D /Y
PAUSE
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

: MY PICTURES
ECHO YOU HAVE CHOSEN TO BACKUP THE MY PICTURES FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /L /E /D /Y
PAUSE
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
GOTO MENU

: next_action

Echo here

PAUSE


My System SpecsSystem Spec
.

28 Oct 2010   #12

XP / Win7 x64 Pro
 
 

You don't need that next_action call or routine. You just need to put an if statement before the end of each sections GOTO command that checks if the command line variable is set, if not it goes back to the menu, otherwise it goes to the next section in an automated fashion. Again, that is what my posts earlier describe rather than having to put a whole new subsection that just adds duplicate code to the program, but I can only lead a horse to water.
My System SpecsSystem Spec
28 Oct 2010   #13

win7
 
 

@FliGi7, The OP changed their requirement in their fourth post on page 1 so that they could jump to a new code section on timeout occurring, that is why I posted my suggestion. Had the requirement stayed the same I would not have suggested the action I did.
My System SpecsSystem Spec
.


28 Oct 2010   #14

XP / Win7 x64 Pro
 
 

Totally understood. I wasn't addressing that toward you, you are simply helping like I am. I was just saying that my solution doesn't require the extras that are coming about from the change the OP wants or thinks he needs now. If I'm understanding his problem correctly, following my instructions will do exactly what he wants with the least amount of extra code added. Or, I could be wrong and he could want something different that I'm not understanding.
My System SpecsSystem Spec
28 Oct 2010   #15

Windows 7 64bit
 
 

FliGi7 your spot on with what i am trying to do! to be honest i dont want to set up a duplicate command of all the menus that i have created for when the timer runs out. What i am trying to do is if i hit enter before the time runs out i can manually pick out of the 4 menus which one i want to back up and when i set it up on the task schedule and the timer runs out i want a command to run and back up all of the 4 menus automatically. Its just finding the right command to add after the timer runs out and adding something in at the end of every menu.

I know im proberly sounding really confusing sorry

willywombat- thanks so much for your input much appreciated
My System SpecsSystem Spec
28 Oct 2010   #16

XP / Win7 x64 Pro
 
 

@ECHO OFF
ECHO WELCOME TO LIAM'S BACKUP WIZARD

IF %1 == "auto" GOTO ITUNES

GOTO MENU
:MENU
ECHO PLEASE SELECT A COMMAND BELOW BY PRESSING NUMBERS 1-4 FOR THE ITEMS THAT YOU WISH TO BACKUP
ECHO ===== BACKUP MENU LIST =====
ECHO 1. iTUNES MUSIC BACKUP
ECHO 2. MY PICTURES BACKUP
ECHO 3. FOOTBALL MANAGER 2011 BACKUP
ECHO 4. QUIT
SET /P N=TYPE 1, 2, 3 OR 4 THEN PRESS ENTER:
IF "%N%"=="1" GOTO iTUNES
IF "%N%"=="2" GOTO MY PICTURES
IF "%N%"=="3" GOTO FOOTBALL MANAGER 2011
IF "%N%"=="4" GOTO QUIT
:iTUNES
ECHO YOU HAVE CHOSEN TO BACKUP THE iTUNES MUSIC FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /L /E /D /Y
PAUSE
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
IF %1 == "auto" GOTO MYPICTURES
GOTO MENU

: MYPICTURES
ECHO YOU HAVE CHOSEN TO BACKUP THE MY PICTURES FOLDER PRESS ENTER TO CONTINUE
PAUSE
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO THE FOLLOWING FILES WILL BE COPIED
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /L /E /D /Y
PAUSE
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO FILE COPY COMPLETE
IF %1 == "auto" EXIT
GOTO MENU



Without having run this myself to check, that should do what you're asking.

In task scheduler have the command run with the argument auto.

Task Scheduler - Create New Task

You would configure this in #7 of the above tutorial.
My System SpecsSystem Spec
29 Oct 2010   #17

Windows 7 64bit
 
 

Thanks so much mate i will give this a try and let you know who it goes

Thanks again
My System SpecsSystem Spec
30 Oct 2010   #18

Windows 7 64bit
 
 

Hi matey i have created a shortcup to my batch file and whenver i try and add "auto backup" to the end of the target line it keeps say the specified target line is not valid. This is what i have done
"C:\Users\Liam\Desktop\Backup Batch Files\Liam's Auto Backup Wizard.bat auto backup"

In the batch file at the top before the "goto menu" option i have put

IF "%1"=="AUTO BACKUP" GOTO AUTO BACKUP

I have added a auto backup menu at the bottom of the batch file with no prompts

:AUTO BACKUP
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------- >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
XCOPY "E:\Music\iTunes\iTunes Media\Music" "I:\Liam\XCOPY Backup Files\iTunes Music" /E /D /Y >> "I:\Liam\XCOPY Backup Files\iTunes Music\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
XCOPY "E:\Pictures" "I:\Liam\XCOPY Backup Files\My Pictures" /E /D /Y >> "I:\Liam\XCOPY Backup Files\My Pictures\BACKUP LOG.TXT"
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
ECHO %DATE% %TIME% >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT
ECHO ------------------------------ >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
XCOPY "C:\Users\Liam\Documents\Sports Interactive\Football Manager 2011 Demo\games" "I:\Liam\XCOPY Backup Files\Football Manager 2011" /E /D /Y >> "I:\Liam\XCOPY Backup Files\Football Manager 2011\BACKUP LOG.TXT"
CLS

I have also tried entering the following arguments in task schedular
%1
"%1"
Auto Backup

Im kinda new to this so still learning my way around but just cant get it to by pass my standard goto menu
My System SpecsSystem Spec
01 Nov 2010   #19

win7
 
 

Try adding an underscore between the words auto and backup in both the shortcut and in the program. This is because the words auto and backup seperated by a space in the command line would be interpreted as 2 seperate paramenters.
My System SpecsSystem Spec
01 Nov 2010   #20

XP / Win7 x64 Pro
 
 

^ What wily said.

It has to be one contiguous word or it will be interpreted as two separate arguments (separated by a space), which is what it is doing. So your program is seeing that %1== "Auto" and is not hitting that routine.
My System SpecsSystem Spec
Reply

 Quick batch file question




Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 03:14 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33