Help with Batch Script to copy contents of a folder (round robin) to 3 different folders RRS feed

  • General discussion

  • Hello All,

    I am very new to batch scripting. I need to split the contents of a folder(that continuously receives new files) into three different folders on the same computer. I have taken a first cut at the script. See below. The script runs every 60 mins, and does the job.

    The issue I have is that each time the script is run, it reads the whole contents of the source folder all over again.This is not viable in my scenario since files are streaming into the source folder in real time. It is very inefficient to copy all the massive amount of files all over again instead of only the new files that have landed in the source folder. 

    Can you good people here assist me with a way to ensure that only the new additions to the source folder is copied to the destination folders the next time the script runs?  

    my script:

    testsplit = sourcefolder

    file1,file2,file3= destination folders

    @echo off &setlocal

    SET folder=C:\Data\testsplit
    SET target0=C:\Data\splitfiles\file1
    SET target1=C:\Data\splitfiles\file2
    SET target2=C:\Data\splitfiles\file3

    FOR /F "tokens=*" %%G in ('dir "%folder%" /A:-D /B') do (
        SET /A counter+=1
        SET /A pointer=counter%%3
    SET "file=%%~A"
        CALL SET "target=%%target!pointer!%%"
        XCOPY "%folder%\%%G" "!target!"



    • Changed type Bill_Stewart Monday, September 11, 2017 3:24 PM
    • Moved by Bill_Stewart Monday, September 11, 2017 3:24 PM This is not "scripts on demand"
    Saturday, July 8, 2017 8:48 PM

All replies