Quick batch file question

Page 2 of 2 FirstFirst 12

  1. Posts : 660
    win7
       #11

    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 Computer


  2. Posts : 1,814
    XP / Win7 x64 Pro
       #12

    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 Computer


  3. Posts : 660
    win7
       #13

    @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 Computer


  4. Posts : 1,814
    XP / Win7 x64 Pro
       #14

    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 Computer


  5. Posts : 212
    Windows 7 64bit
    Thread Starter
       #15

    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 Computer


  6. Posts : 1,814
    XP / Win7 x64 Pro
       #16

    @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 Computer


  7. Posts : 212
    Windows 7 64bit
    Thread Starter
       #17

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

    Thanks again
      My Computer


  8. Posts : 212
    Windows 7 64bit
    Thread Starter
       #18

    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 Computer


  9. Posts : 660
    win7
       #19

    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 Computer


  10. Posts : 1,814
    XP / Win7 x64 Pro
       #20

    ^ 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 Computer


 
Page 2 of 2 FirstFirst 12

  Related Discussions
Our Sites
Site Links
About 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 04:48.
Find Us