Advertisement

Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Thursday, November 24, 2011

DOS Batch File to Periodically Copy Files to a Location

During a Testing I had to do at my workplace I had to copy files to an input location at a random time so that there would be a constant supply of input files. I did some googling and found out several commands and integrated those together to create a batch file which can do that. The waiting is done using a ping command with a timeout. The timeout is taken from the system environment variable RANDOM so that it pauses for a random amount of time before copying files. After copying files I do a clean up on output files so that the storage is not spiked.

:again

SET COPYCMD=/Y

ping 123.45.67.89 -n 1 -w %RANDOM% > nul

xcopy <Source Folder with Files>\* <Destination Folder with Files> /s 

del /q <Folder Where Files to be Deleted Available>\*

goto again


COPYCMD Environment Variable is used to Enable overwriting of existing files without prompting.

No comments: