Need some help making a short batch file

Page 1 of 2 12 LastLast
  1. reddwarf4ever's Avatar
    Posts : 1,235
    windows 10 PRO
       #1

    Need some help making a short batch file


    Hi

    I need help with a rather short batchfile.

    I need Two actually each with subtle differences..

    Batch file A

    1-Check the date of the file on a USB pen in folder B is newer than the same file on the PC if it is then replace the file
    2-run a .exe program ( I hope the batch file doesn’t move forward until the .exe program ends)
    3-1-Check the date of the file on a PC pen is newer than the same file on the USB pen Folder A if it is then replace the file

    Batch file B

    1-Check the date of the file on a USB pen in folder A is newer than the same file on the PC if it is then replace the file
    2-run a .exe program ( I hope the batch file doesn’t move forward until the .exe program ends)
    3-1-Check the date of the file on a PC pen is newer than the same file on the USB pen Folder B if it is then replace the file

    the reasoning for this is that Inhave a car theory test Program installed in two computers but want to be able to continue the progress, whichever computer I am using, as the save file is in Appdata, then I can, take this with me to the other PC, the date check is just a precaution, in case the same PC is used for more than one session and the file has not been updated on the othe PC.

    I hope it sounds more complicated than it is.......

    I am assuming that when the .exe is launched in the batch file that the next ‘line’ to backup the file is not executed until the program is terminated.

    thanks in advance
      My Computer

  2. das10's Avatar
    Posts : 2,760
    Win 10 pro 20H2
       #2

    You could explore the possibilities using robocopy, for example


    Batch file A:


    "ROBOCOPY.EXE" "Z:\Folder B" "C:\data\path" "myfile.abc" /XO
    start "dvl" /WAIT "C:\path of dvl\dvl.exe"
    "ROBOCOPY.EXE" "C:\data\path" "Z:\Folder A" "mydata.dat" /XO

    pause



    Batch file B -similar to above, adjust your paths according to your need:


    "ROBOCOPY.EXE" "Z:\Folder A" "C:\data\path" "myfile.abc" /XO
    start "dvl" /WAIT "C:\path of dvl\dvl.exe"
    "ROBOCOPY.EXE" "C:\data\path" "Z:\Folder B" "mydata.dat" /XO

    pause




    NOTE:
    Replace Z with the USB drive letter (it has to be the same letter on both PC's).
    Include path names with spaces in quotes.
    With Robocopy, the folder path should not include a terminating backslash ie use "Z:\Foder B" and not "Z:\Folder B".
    Starting the program with /WAIT option will wait for the program to terminate before carrying on with the next command.
    The file to be copied is myfile.abc again use quotes if file name has spaces.
    Th robocopy /XO option makes sure the file is copied only if it is newer.
    Pause at the end of the batch file allows you to see the actions taken (useful for seeing errors etc)


    I would first back up my original files/folders and test these batch files on some disposable folders and files to see how they work, as ROBOCOPY is quite powerful and if you set the wrong options you may end up with over-writing the wrong files.


    ROBOCOPY.EXE is located in C:\windows\system32

    for help run the following in a command box
    robocopy /?
    start /?

    It may turn out that you may have passed your dvl test, by the time these batch files get working !

    Good luck.
      My Computer

  3. das10's Avatar
    Posts : 2,760
    Win 10 pro 20H2
       #3

    edit : can't make this show properly in my post- to clarify:

    With Robocopy, the folder path should not include a terminating backslash ie use Z:\Foder B and not Z:\Folder B\
      My Computer

  4. Berton's Avatar
    Posts : 10,562
    Win10 Pro Versions 2004 and 2009/20H2, Win10 Pro IP_Dev, Win10 Home 1909
       #4

    If you put Pause on a line [by itself] in a batch file it will halt at that point and prompt to do a key press before continuing to run. Using Pause as the last line will keep the window open.
    My sample for test.bat file on the Desktop:
    cd\
    C:
    dir
    pause
    dir
    pause
      My Computers

  5. reddwarf4ever's Avatar
    Posts : 1,235
    windows 10 PRO
    Thread Starter
       #5

    Thanks DAS10, looks like that’s the solution.....will give it a try very soon


    also don’t want to keep the Dos window open, so do I use @echo off in the first line.....also don’t think I need the pause ???

    1-ROBOCOPY.EXE" "Z:\Folder B" "C:\data\path" "myfile.abc" /XO do I need to specify the file name in folder B ?
    2-start "dvl" /WAIT "C:\path of dvl\dvl.exe" what does start”dvi” do?
    3-"ROBOCOPY.EXE" "C:\data\path" "Z:\Folder A" "mydata.dat" /XO guess I use the same file naming in this line in line 1 ?


    Once line 2 is executed would it wait till the program ends Withiut the wait command ?


      My Computer

  6. das10's Avatar
    Posts : 2,760
    Win 10 pro 20H2
       #6

    You would need the command window open in order to process all the commands one after the other. There may be a way to hide that command window using a third party utility, though I haven't investigated that as I really like to see what the batch files are doing.

    The pause can be removed once the batch file works properly. Pause allows you to see any errors thats all; or as Berton pointed out, if you insert it between command lines it allows you to step through commands one by one. You can remove pause after the batch works properly.

    You don't need to specify the file name in folder B; it gets copied with the original name

    If its a whole folder that needs copying then you don't use the file name/s so the command would be:
    ROBOCOPY.EXE" "Z:\Folder B" "C:\data\path" /XO

    The start "dvl" is to give a title to the command box.(For more info enter start/? to see help in a command box or see this link
    Start - Start a program - Windows CMD - SS64.com)

    "3-"ROBOCOPY.EXE" "C:\data\path" "Z:\Folder A" "mydata.dat" /XO guess I use the same file naming in this line in line 1 ?"
    -Yes, sorry was my error it should have been "myfile.abc"

    You really need the WAIT command, or else, the following command will be executed and if the dvl program is running, your data file may be locked and/or not saved/copied properly.
      My Computer

  7. Callender's Avatar
    Posts : 4,097
    N/A
       #7

    FYI: you might just want to place this executable on your USB:

    SimplySync Backup

    How you use it would depend upon the file names. Are they fixed or do the file names change?
      My Computer

  8. Callender's Avatar
    Posts : 4,097
    N/A
       #8

    FYI: there is also this:

    http://dimiodati.altervista.org/zip/dsynchronize.html

    Place on USB. Add folder pair. Choose options. Include "Ask before delete" "Ask before add" "Ask before replace" and use bi-directional sync.

    Need some help making a short batch file-dsync.jpg

    Need some help making a short batch file-dsync2.jpg
      My Computer

  9. reddwarf4ever's Avatar
    Posts : 1,235
    windows 10 PRO
    Thread Starter
       #9

    Hi
    filenames stay the same
      My Computer

  10. das10's Avatar
    Posts : 2,760
    Win 10 pro 20H2
       #10

    [QUOTE=Callender;1519529]FYI: there is also this:

    http://dimiodati.altervista.org/zip/dsynchronize.html

    Place on USB. Add folder pair. Choose options. Include "Ask before delete" "Ask before add" "Ask before replace" and use bi-directional sync.

    Yes, agreed, a more elegant solution.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 09:15.
Find Us




Windows 10 Forums