If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address

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.



ping -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: