Search code examples
loopsbatch-filecopyrepeat

Write a batch file to repeatedly copy files


I am trying to make a batch/script file that will repeatedly COPY a file from one location to another. I don't care if it overwrites the file or if it doesn't copy if the file exists. But I want a batch file that copies a file within a loop.

How do I go about making a batch file to repeatedly copy a file?

loop:
copy /y a.txt c:/b.txt
Goto loop

It runs once.


batch.bat:

rere:
copy /y c:\folder1\abc.txt c:\folder2\abc.txt
pause
goto rere

output when double-clicking batch.bat:

C:\Users\User\Desktop> rere:
'rere:' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\User\Desktop> copy /y c:\folder1\abc.txt c:\folder2\abc.txt
        1 file(s) copied.

C:\Users\User\Desktop> pause
Press any key to continue . . .

Solution

  • :loop
    copy file1 file2
    Goto loop
    

    is how. See goto /? and copy /?.