1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

NEED HELP WITH MY BATCH APP...!!!

Discussion in 'Windows - General discussion' started by Deviouz, Mar 28, 2007.

  1. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    I need some help with this quick batch app im making that uses HSTART.EXE & ROBOCOPY.EXE
    Basicaly it checks the Recycle Bin and all removable storage drives for files & then copies all of them to C:\0\1
    But i need to figure out how to prevent Robocopy.exe from running the same command thread twice at the same time
    when the bacth reapeats over on itself again, if its already in the process of copying files over..
    How can i do this..??

    {> BATCH CODE APP <}

    :UP
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe C:\RECYCLER C:\0\1\REC /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe E: C:\0\1 /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe F: C:\0\1 /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe G: C:\0\1 /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe H: C:\0\1 /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe I: C:\0\1 /XX /mir /r:0"
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\Robocopy.exe J: C:\0\1 /XX /mir /r:0"
    PING 127.0.0.1 -n 5
    cls
    GOTO UP
     
  2. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    Use the /WAIT switch so that the start command waits till the program finishes.

    start /WAIT %MYFILES%\hstart.exe..........

    at the command prompt, type

    start /?

    to get a list of options and switches.

    But wait... (or WAIT) ;-)

    you can use the /WAIT switch with hstart. Why are you using start to run hstart?

    Can't you just do this:-

    %MYFILES%\hstart.exe /nowindow /WAIT "%MYFILES%\Robocopy.exe C:\RECYCLER C:\0\1\REC /XX /mir /r:0"

    etc
    etc
    etc

    Don't see why you need to START HSTART...

    Even better put hstart.exe on your PATH and you can drop the %MYFILES% variable as well. And just use "hstart" without any extension. (even more like START, as the writer intended)

    If you are fooling around with batch and command scripting, you'll need to find out about the PATH sooner or later...

    Just my 2 [euro] cents worth.




     
    Last edited: Mar 28, 2007
  3. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    the reason i use start is because it runs all the commands at once instead of waiting for the first one to complete to move on to the next.. that way if there are multiple devices plugged into the PC at the same time this APP can copy all of them at the same time..

    also i like to have the other 2 apps rapped inside the quick batch app so everything is all together one deployable unit.


    the /wait command aint really helping man, the robocopy.exe processes keep stakin up in the Processes Manager..
     
    Last edited: Mar 28, 2007
  4. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    So before Robocopy is let loose on a folder, you need to know if it is still working on that folder from the previous time around the loop, and if so, skip to the next one, so that any one time you have no more than 7 Robocopy threads active?

    I think that you are going to have to accept some extra complexity in your batch file, or abandon the idea of having all the threads running at once. (Why is this so important?)




     
  5. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    Yes thats exactly what i want to do, but i want it all done silently in the background with no pop-up prompts or anything...

    Is there a switch of some sort thats looks to see if the process thread is already running and skips it from excuting again until its finished completing its tasks..??

    is this possible with batch or will i have to do this in some other coding language..



     
  6. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    you can use tasklist and pipe the results to FIND and use the && operator to perform a task if the program is running.

    && is an IF operator: if the first part of the line (before the &&) terminates with a success indication, then the second part (after the &&) is executed.

    In this example if the program is found in the output of the tasklist command (ie is running) then the message is echoed:-

    tasklist | find "Robocopy.exe" && echo "Yes, Robocopy.exe is running"

    Spelling of text to find is case sensitive unless you use the /i switch with find (find /i).

    The problem of which one of the Robocopy threads is the one we want to test could be got around if you have copies called cRobocopy.exe, eRobocopy.exe, fRobocopy.exe, etc... each one used on a particular folder...

    (for example)

    tasklist | find /i "cRobocopy.exe" && goto skipc
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\cRobocopy.exe C:\RECYCLER C:\0\1\REC /XX /mir /r:0"
    :skipc
    tasklist | find /i "eRobocopy.exe" && goto skipe
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\eRobocopy.exe E: C:\0\1 /XX /mir /r:0"
    :skipe
    (etc)
     
    Last edited: Mar 28, 2007
  7. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    COOL thanks man ...!!!
    THIS SEEMS TO WORK

    {Except on one of my pc's it keeps giving me an "ERROR: Class not registered." when i do a TASKLIST in CMD. but my other PC accepts the command & works just fine....its odd becuz both PC's have the same OS XP PRO }

    {>NEW BATCH CODE <}

    :UP

    tasklist | find /i "R-copy-1.exe" && goto SKIP-1
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-1.exe C:\RECYCLER C:\0\1\REC /XX /mir /r:0"
    :SKIP-1

    tasklist | find /i "R-copy-2.exe" && goto SKIP-2
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-2.exe E: C:\0\1 /XX /mir /r:0"
    :SKIP-2

    tasklist | find /i "R-copy-3.exe" && goto SKIP-3
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-3.exe F: C:\0\1 /XX /mir /r:0"
    :SKIP-3

    tasklist | find /i "R-copy-4.exe" && goto SKIP-4
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-4.exe G: C:\0\1 /XX /mir /r:0"
    :SKIP-4

    tasklist | find /i "R-copy-5.exe" && goto SKIP-5
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-5.exe H: C:\0\1 /XX /mir /r:0"
    :SKIP-5

    tasklist | find /i "R-copy-6.exe" && goto SKIP-6
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-6.exe I: C:\0\1 /XX /mir /r:0"
    :SKIP-6

    tasklist | find /i "R-copy-7.exe" && goto SKIP-7
    start %MYFILES%\hstart.exe /nowindow "%MYFILES%\R-copy-7.exe J: C:\0\1 /XX /mir /r:0"
    :SKIP-7

    PING 1 -n 5
    cls
    GOTO UP



    I just need now to find a way for Robocopy.exe to not overwrite files in the destination DIR , if in the source it copies files with same names that are in the Destination DIR, but rather renames the new copied files..
    You know the switch fo that at all..???
     
  8. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    That error normally means the version is XP Home. Is tasklist.exe present in the c:\windows\system32 folder? If not, you could copy over an XP pro version or download it from

    http://www.computerhope.com/download/winxp/tasklist.exe

    Maybe that would work?

    By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.

    http://www.ss64.com/nt/robocopy.html

    I have looked through the Robocopy switches and I cannot see an obvious way to do that, I will think about it.




     
  9. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    this is odd, my OS is XP PRO and c:\windows\system32\tasklist.exe does exist, but i still get "ERROR: Class not registered." when i try run it in CMD on my laptop XP PRO PC....
    NOT realy a big deal to me though anyway..


    ""By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.""

    Say i have a USB thumb drive with 1 JPG file on it at "F:\PIX\1.jpg"
    when i first plug in the USB drive, my App will auto copy it to "C:\0\1\1.jpg"

    But if i delete "F:\PIX\1.jpg" on the USB Drive and replace it with a totally new-differnt 1.jpg file.. when my APP picks it up to copy it over the robocopy deletes the already existing "c:\0\1\1.jpg" and replaces it with the new "F:\PIX\1.jpg"

    But i don't want that to happen though.. I want either one of the same named files to be auto renamed so nothing in the destination folder ever gets auto deleted or replaced..

     
  10. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    I think you are finding the limitations of Robocopy, which has little built-in intelligence.

    It seems to me that you could use the /XC and /XN switches to exclude changed and newer files, and the /V switch to produce a log file, which will report skipped files, including the full path names if you add the /FP switch, which will be the ones needing a rename, and then process that log file.

    [later]

    I am playing around with my pen drive. I have found a way to skip, and make a list of, those files that will need renaming.

    I created files called new.txt and new1.txt and added them to my pen drive. Then I did a first run of Robocopy. Then I changed new.txt and new1.txt and ran again.

    I used the above ideas plus the /L switch to just list without copying anything, plus switches to exclude header, summary, file size, folder names from the log, which is echoed to the console... (see Robocopy reference)

    --This is all very crude and just a quick first try--

    I:\>Robocopy.exe U:\ I:\robtest\pdrive /L /NDL /NS /NJH /NJS /FP /XX /XC /XN /XO /V /mir /r:0

    newer U:\test\new.txt
    newer U:\test\new1.txt
    same U:\AUTOEXEC.bat
    same U:\COMMAND.COM
    same U:\CONFIG.sys

    [about 150 lines chopped]

    ... and a pipe to find lines with the word "newer" in them -

    I:\>Robocopy.exe U:\ I:\robtest\pdrive /L /NDL /NS /NJH /NJS /FP /XX /XC /XN /XO /V /mir /r:0 | find "newer"

    newer U:\test\new.txt
    newer U:\test\new1.txt

    [the complete output]

    Further, I can redirect the output to a text file by using the > redirection operator...

    (Of course you could just use the /LOG:file switch for this)

    I:\>Robocopy.exe U:\ I:\robtest\pdrive /L /NDL /NS /NJH /NJS /FP /XX /XC /XN /XO /V /mir /r:0 | find "newer" > rob.txt

    Let's see the text file...

    I:\>type rob.txt
    newer U:\test\new.txt
    newer U:\test\new1.txt

    So next is to extract just the filenames and do something with them.

    Probably in a FOR loop along these lines (this one just echoes the names) but we can do lots of clever things with the filename including changing drive letter etc and appending stuff to the destination name)

    for /F "delims==" %%a in (rob.txt) do (

    echo %%a

    )

    At the moment I am thinking of applying a timestamp of ddmmyyhhmmss as an addition to the file name... (You'd have to be very quick to defeat that)

    Update later.
     
    Last edited: Mar 30, 2007
  11. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    seems all a lil to confusing to me...

    Is there a way to just simply put in a batch code after the copying code is done to rename the folder that the files were just copied into, to that of the current time & date...like: 2007-04-26__12.08.55.pm

    so that way after the copying is done the folder is time-stamped-named and if the Removable Storage Drive is plugged back in again with newer files on it but with same names as the old files, they will now be copied into an entirely separate folder eliminating the fear of any files getting overwritten...

    is this possible at all..???
     
  12. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    anybody know at all..???
     
  13. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
  14. Deviouz

    Deviouz Member

    Joined:
    May 31, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    16
    didn't really understand much at that link but I found this which seemed to work. http://talk.bmc.com/blogs/blog-gentle/anne-gentle/dos-timestamp-tips

    ------------------------------------------------

    REM where yymmdd_hhmmss is a date_time stamp like 030902_134200
    set hh=%time:~0,2%
    REM Since there is no leading zero for times before 10 am, have to put in
    REM a zero when this is run before 10 am.

    if "%time:~0,1%"==" " set hh=0%hh:~1,1%
    set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%_%hh%%time:~3,2%%time:~6,2%
    ren c:\0 %yymmdd_hhmmss%
    -------------------------------------------------
    it works...
    But how can i change this code to make it timestamp the folder like this: YYYY-MM-DD_HH.MM.SS
    EX. 2007-05-05_12.30.25
     
  15. hamubra

    hamubra Member

    Joined:
    Oct 31, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    11
    Please try to understand the help for the SET command,
    especially this example, extracted from the "set /?" output:

    The author extendedly makes use of this 'midstring' function.

    You only have to adapt it to your date and time format, dependent of your regional date and time settings.
    You can try them out by the "set %date%" command, whereas %date% is a builtin variable, see "set /?" output at the very end.
    Same applies for %time%.

    Hope that helps.
     
  16. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    Previous message was 6 months ago! I think they must have understood by now.

     
  17. hamubra

    hamubra Member

    Joined:
    Oct 31, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    11
    I think too.
    Unfortunately I noticed it very late, and the answer was ready to be sent. I thought that it might help anyway, and clicked on Submit.
    Sorry if this brought any inconvenience.

    BTW: today I worked on a script using Robocopy or XXcopy for 'cloning' directory trees, and found this thread when googling for examples...

    Hartmut
     
  18. Indochine

    Indochine Regular member

    Joined:
    Dec 21, 2006
    Messages:
    1,447
    Likes Received:
    0
    Trophy Points:
    46
    I have found Xxcopy very useful myself.
     

Share This Page