Batch file copy cmds not working correctly.

Page 1 of 2 12 LastLast

  1. Posts : 73
    Windows 7 Ultimate x64 SP1
       #1

    Batch file copy cmds not working correctly.


    I'm trying to learn batch cmds and i figured the best way to learn is to make one.
    I started this about 6 months ago and got it to half work. Tried to get it to work and gave up. Saw it while cleaning my drives up and figured i give it another shot.

    Heres the problem.
    After choosing 1 and letting it complete, it will go back to the menu like i want it to. But when i go to choose 2 it will do 1 again. If i choose 2 it will redo 1 again. Same for if i close it out and choose 2 then let it finish then choose 3 it will do 2 again same if i chose 3 first. When i close out and do roaming or local it will either copy over half the folder or copy over the folder plus the ubisoft folder.

    So trying to fix it it now returns Invalid drive specification error. Even when i chose 7 to exit on start up it gives an Invalid drive specification error.

    I was trying to have the batch file after getting everything right to copy all the locations to the folder the batch file is in. I was also going to make it where it copied it back to the original locations so it will be a back up and restore.

    So can anyone help me and see where i went wrong? I figured if i can get this right then restoring them would just mean a reversal of the codes.

    Game Saves Backup & Restore.bat
      My Computer


  2. Posts : 396
    Windows 7/8.1/10 multiboot
       #2

    The problem is right after the command:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    That command tells the batch file to get the user's selection (1-6), but then there are no subsequent commands telling the script to branch elsewhere depending on that selection. As a result, regardless of the selection the script always executes the immediately following commands:
    Code:
    IF %M%==1 set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    The script never gets below that because the first "GOTO Menu" always short-circuits it.

    To show you what's happening, substitute the following code for the entire bottom half of your script:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    
    cls
    echo You selected: 
    
    IF %M%==1 echo 1
    echo you should only be here if 1 is selected
    GOTO Menu
    IF %M%==2 echo 2
    GOTO Menu
    IF %M%==3 echo 3
    GOTO Menu
    IF %M%==4 echo 4
    GOTO Menu
    IF %M%==5 echo 5
    GOTO Menu
    IF %M%==6 echo 6
    GOTO Menu
    IF %M%==7 EXIT
    Pause
    This is basically your code except I've stripped out all the "meat" of what each selection is supposed to perform just to focus on the program flow. Run that script and notice the responses as you press each selection.

    Now try replacing the bottom half of your script with the following instead:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    
    cls
    echo You selected: 
    
    goto %M%
    
    :1
    echo 1
    GOTO Menu
    :2
    echo 2
    GOTO Menu
    :3
    echo 3
    GOTO Menu
    :4
    echo 4
    GOTO Menu
    :5
    echo 5
    GOTO Menu
    :6
    echo 6
    GOTO Menu
    :7
    EXIT
    Pause
    Now your program flow branches via the "goto %M%" to the additional labels identifying each branch. Run this script and notice the difference.

    BTW, you can then also eliminate the "IF %M%==" conditions because the program is only going to get to that branch when the condition is met anyway, so the "IF %M%" becomes redundant.
      My Computer


  3. Posts : 3,788
    win 8 32 bit
       #3

    look at AutoIt Scripting Language - AutoIt it has lots of built incmds to make life simple and you can have graphics and more and its free with lots of support and you can create an .exe with it
      My Computer


  4. Posts : 16,160
    7 X64
       #4

    Another way is use brackets following the IF statement


    IF %M% EQU1 (set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    )
      My Computers


  5. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #5

    dg1261 said:
    The problem is right after the command:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    That command tells the batch file to get the user's selection (1-6), but then there are no subsequent commands telling the script to branch elsewhere depending on that selection. As a result, regardless of the selection the script always executes the immediately following commands:
    Code:
    IF %M%==1 set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    The script never gets below that because the first "GOTO Menu" always short-circuits it.

    To show you what's happening, substitute the following code for the entire bottom half of your script:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    
    cls
    echo You selected: 
    
    IF %M%==1 echo 1
    echo you should only be here if 1 is selected
    GOTO Menu
    IF %M%==2 echo 2
    GOTO Menu
    IF %M%==3 echo 3
    GOTO Menu
    IF %M%==4 echo 4
    GOTO Menu
    IF %M%==5 echo 5
    GOTO Menu
    IF %M%==6 echo 6
    GOTO Menu
    IF %M%==7 EXIT
    Pause
    This is basically your code except I've stripped out all the "meat" of what each selection is supposed to perform just to focus on the program flow. Run that script and notice the responses as you press each selection.

    Now try replacing the bottom half of your script with the following instead:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    
    cls
    echo You selected: 
    
    goto %M%
    
    :1
    echo 1
    GOTO Menu
    :2
    echo 2
    GOTO Menu
    :3
    echo 3
    GOTO Menu
    :4
    echo 4
    GOTO Menu
    :5
    echo 5
    GOTO Menu
    :6
    echo 6
    GOTO Menu
    :7
    EXIT
    Pause
    Now your program flow branches via the "goto %M%" to the additional labels identifying each branch. Run this script and notice the difference.

    BTW, you can then also eliminate the "IF %M%==" conditions because the program is only going to get to that branch when the condition is met anyway, so the "IF %M%" becomes redundant.
    So after 1 in your code do i put set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"?
    Like i said i'm just learning this. But i see i didn't learn much at all from my research except the wrong way to do stuff.

    I used this as the basis of my batch file that is why i thought it was good.

    Batch Files - Create a Menu to Execute Commands
      My Computer


  6. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #6

    SIW2 said:
    Another way is use brackets following the IF statement


    IF %M% EQU1 (set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    )
    If i do that, i only did the first one as a test.

    I get this error.

    '"C:\Program Files (x86)\Steam\userdata"' is not recognized as an internal or external command,

    operable program or batch file.

    Here is what i did exact as yours. And got error above.

    (set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    )
      My Computer


  7. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #7

    samuria said:
    look at AutoIt Scripting Language - AutoIt it has lots of built incmds to make life simple and you can have graphics and more and its free with lots of support and you can create an .exe with it
    I'll look into this and see what i scripting language i have to learn to use it.
      My Computer


  8. Posts : 396
    Windows 7/8.1/10 multiboot
       #8

    SnakeFist said:
    So after 1 in your code do i put set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"?
    Correct. Where you have:
    Code:
    IF %M%==1 set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    replace with:
    Code:
    :1
    set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    (Disclaimer: I didn't troubleshoot those commands, but I'm assuming you had at least the "1" option working correctly and your only issue was getting the "2" through "6" options working similarly. I trust there really exists a folder called "F:\Save Game Files\Goes Back To Steam Userdata", for instance.)

    What this change does is setup a jump destination labeled "1" for the commands you want to execute when "1" is pressed. Note you're only going to get here if %M% is 1, so the "if %M%==1" is redundant here and can be eliminated.

    Make similar changes for the "2" through "7" subsections.

    You want each of these subsections to execute if and only if the corresponding number is selected from the menu. To accomplish that kind of discrimination, precede the whole lot with a "goto %M%" jump instruction right after the "SET /P M=Type" command, ala:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    cls
    goto %M%
    What the SET command does is set an environment variable M to whatever number is pressed (i.e., it will perform a "set M=1", or "set M=2", or whatever), then the following "goto %M%" tells the script to jump to the corresponding subsection (i.e., it will translate to "goto 1", or "goto 2", or whatever).

    The "cls" is optional, but I added it just to clear the display after each selection to make it look a little cleaner.
      My Computer


  9. Posts : 73
    Windows 7 Ultimate x64 SP1
    Thread Starter
       #9

    dg1261 said:
    Correct. Where you have:
    Code:
    IF %M%==1 set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    replace with:
    Code:
    :1
    set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    (Disclaimer: I didn't troubleshoot those commands, but I'm assuming you had at least the "1" option working correctly and your only issue was getting the "2" through "6" options working similarly. I trust there really exists a folder called "F:\Save Game Files\Goes Back To Steam Userdata", for instance.)

    What this change does is setup a jump destination labeled "1" for the commands you want to execute when "1" is pressed. Note you're only going to get here if %M% is 1, so the "if %M%==1" is redundant here and can be eliminated.

    Make similar changes for the "2" through "7" subsections.

    You want each of these subsections to execute if and only if the corresponding number is selected from the menu. To accomplish that kind of discrimination, precede the whole lot with a "goto %M%" jump instruction right after the "SET /P M=Type" command, ala:
    Code:
    SET /P M=Type 1, 2, 3, 4, 5 or 6 then press ENTER:
    cls
    goto %M%
    What the SET command does is set an environment variable M to whatever number is pressed (i.e., it will perform a "set M=1", or "set M=2", or whatever), then the following "goto %M%" tells the script to jump to the corresponding subsection (i.e., it will translate to "goto 1", or "goto 2", or whatever).

    The "cls" is optional, but I added it just to clear the display after each selection to make it look a little cleaner.
    Ok i went ahead and did the changes you said to make.

    Code:
    SET /P M=Type 1, 2, 3, 4, 5, 6 or 7 then press ENTER:
    cls
    goto %M%
    :1
    set drive=F:\Save Game Files\Goes Back To Steam Userdata
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Steam\userdata" "%drive%"
    GOTO Menu
    :2
    set drive=F:\Save Game Files\Goes Back To Documents Folder
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "%userprofile%\documents" "%drive%"
    GOTO Menu
    :3
    set drive=F:\Save Game Files\Goes Back To Saved Games Folder
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "%userprofile%\Saved Games" "%drive%"
    GOTO Menu
    :4
    set drive=F:\Save Game Files\Goes Back To AppData Folder
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "%AppData%\Local" "%drive%"
    GOTO Menu
    :5
    set drive=F:\Save Game Files\Goes Back To AppData Roaming Folder
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "%AppData%\Roaming" "%drive%"
    GOTO Menu
    :6
    set drive=F:\Save Game Files\Goes Back To Ubisoft Save Games Folder
    set backupcmd=xcopy /s /r /y /k /v /e /i
    %backupcmd% "C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\savegames" "%drive%"
    GOTO Menu
    :7
    EXIT
    Pause
    Everything is working except the appdata\local and appdata\roaming options.
    When i choose option 4 i will get the error File not found - Local
    0 File(s) copied
    When i choose option 5 i will get the error File not found - Roaming
    0 File(s) copied
    Other then them 2 options not working the rest work great.


    The folder F:\Save Game Files\Goes Back To Steam Userdata is just for internal testing.

    So basically each location that gets backed up goes into it's own folder inside the save game files folder.

    I know that not everyone will have an F:\ drive. I used that location for internal testing purposes. What i want to do is after i get everything working is to have the folder save game files created inside the same folder as where the batch file is.
    So the batch file and the save game files are in the same folder cause i also want to if possible to also make it to restore the save game files back to the correct folders where they was backed up from.

    So after i get everything correct. I want to add options 7 through 12 to restore what was backed up in options 1 through 6. So 13 will become exit. To make it easy for people who don't know much about computers to be able to backup and restore their save game files with one batch file.
      My Computer


  10. Posts : 396
    Windows 7/8.1/10 multiboot
       #10

    SnakeFist said:
    Ok i went ahead and did the changes you said to make.
    [...]
    Everything is working except the appdata\local and appdata\roaming options.
    When i choose option 4 i will get the error File not found - Local
    0 File(s) copied
    When i choose option 5 i will get the error File not found - Roaming
    0 File(s) copied
    Other then them 2 options not working the rest work great.
    For troubleshooting purposes, temporarily precede the "%backupcmd% ..." lines in the 4 and 5 subsections with "echo %backupcmd% ..." This will tell the script to echo on screen what command it's designed to perform, in lieu of actually trying to perform it.

    This can be system-dependent, but on my system it reveals subsection 4 is trying to execute:
    xcopy /s /r /y /k /v /e /i "C:\Users\Dan\AppData\Roaming\Local" "F:\Save Game Files\Goes Back To AppData Folder"

    while subsection 5 is trying to execute:
    xcopy /s /r /y /k /v /e /i "C:\Users\Dan\AppData\Roaming\Roaming" "F:\Save Game Files\Goes Back To AppData Roaming Folder"

    Obviously, these commands are only going to work if these folders exist:
    "C:\Users\Dan\AppData\Roaming\Local"
    "F:\Save Game Files\Goes Back To AppData Folder"
    "C:\Users\Dan\AppData\Roaming\Roaming"
    "F:\Save Game Files\Goes Back To AppData Roaming Folder"
    The two C: folder locations look particularly suspicious to me. Check your system to see if Roaming\Local and Roaming\Roaming actually exist. They don't on mine ... hence, the error messages.

    Looking at your script, I see those subsections are drawing part of the filespec from %AppData%, so that's where you're probably running into trouble. You need to modify that or use something else.


    Technical aside: your filespec in subsection 4 finishes with "Local", but you're not telling the OS whether that refers to a file or a folder. If there's a folder named "Local" at "C:\Users\Dan\AppData\Roaming" it will correctly guess you want all the files in the "Local" folder, but if there's no such folder there, it will assume you must be referring to a file named "Local" at that location.

    Since my system has neither a file nor a folder called "Local" in "C:\Users\Dan\AppData\Roaming", the OS is assuming your script is referring to a file and hence the "File not found - Local" error message.

    The same goes for subsection 5.
      My Computer


 
Page 1 of 2 12 LastLast

  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 20:38.
Find Us