Robocopy logon script – copy all files, except 1, unless it doesnt exist

Currently have a GPO that calls a batch file at logon, that copyies files from one folder to another:

Robocopy "C:\logon" "X:\user1" /mir /r:1 w:1
Exit

This overwrites all the files in the destination, which is what I want, but I need to exclude one file, call if file1, if it already exists in the destination. So user1 contains all the files from C:\logon, it will overwrite all but file1. New user2 doesnt contain any, it will copy all contents, including file1 into the X:\user2 folder.

Can robocopy handle such a request? Or would I be looking at a different solution, that hopefully won’t impact logon time too much.

Thank you.

Answer

I’m not aware of a switch in robocopy to do that, but you can test for the file, and invoke robocopy with different options to accomplish that result:

if not exist x:\user1\file1.txt Robocopy "C:\logon" "X:\user1" /mir /r:1 w:1
if exist x:\user1\file1.txt Robocopy "C:\logon" "X:\user1" /mir /r:1 w:1 /xf file1.txt

Attribution
Source : Link , Question Author : soMuch2Learn , Answer Author : Clayton

Leave a Comment