0

Dears,

I have a code that works for copying the files, from one to another folder, it also search if the file exists in the subfolders.

But I want it to check if files are modified and replace the old ones.

This is the code that works for me.

I would appreciate for your help.

@echo off
for %%I in ("C:\test1\*") do (
    dir "C:\test2\%%~nxI" /A-D /B /S >nul 2>nul
    if errorlevel 1 copy "%%I" "C:\test2\" >nul
)
Rostuse
  • 1
  • 1
  • 1
    Take advantage of the archive attribute, similar to what I did [here](https://stackoverflow.com/questions/36951081/batch-script-that-monitors-for-file-changes/36952026#36952026) or [here](https://stackoverflow.com/questions/36480736/continuously-check-a-file-modified-or-not-using-batch-file/36482428#36482428) – Stephan Feb 05 '21 at 07:41
  • 1
    Pretty sure you could do this in a single line of code if you used `XCOPY` or `ROBOCOPY`. Regardless of that, I am surprised that you didn't see the `EXIST` option when you were reading the help file for the `IF` command. – Squashman Feb 05 '21 at 13:48
  • @Squashman I could appreciate you help. Thanks – Rostuse Feb 05 '21 at 14:10

0 Answers0