0

I've been trying to get the syntax right, but I'm having issues. Not only am I not getting the syntax right, but I would like this script to:

  1. Locate all files of a certain criteria on All Drives in a network
  2. check to see if the file is the updated file (or new file)
  3. if it is NOT the new or updated file, locate the new file and replace it

ALSO! If I can get this to work on a schedule, such as every 6 hours... that would be a real help

I got this code to work once, but I changed it a couple times and saved over it.

@echo off
SETLOCAL
cls

:locate_old
for /d /r Z:\ %%a in (*) do if exist "%%~fa\old.file" set "oldFile=%%~fa\old.file"
if not defined oldFile (
echo old file not found...
) else (
echo old file found&GOTO oldFileCheck
)

:oldFileCheck
find "old file text" "%oldFile%" && echo old file is already updated || GOTO findNewFile

:findNewFile
for /d /r Z:\ %%a in (*) do if exist "%%~fa\new.file" set "newFile=%%~fa\new.file"
if not defined newFile (
echo no new file detected...
) else (
echo new file located...&GOTO fileSwap
)

:fileSwap
copy /y "%newFile%" "%oldFile%" && echo file updated || file not updated
modusCell
  • 13,151
  • 9
  • 53
  • 80

1 Answers1

0

If I understand your requirement, you want to replace all "old.file" files on Z:\ with "new.file" files if they aren't updated already. This is untested:

@if not defined debug_batch_files echo off
REM You can set debug_batch_files to 1 and quickly see verbose execution
pushd Z:\
for /f "delims=" %%a in ('dir /b /s /a-d new.file') do echo xcopy /D /Y "%%~fa" "%%~dpaold.file"
REM Remove "echo" from the above line if it displays the right paths.
popd
Parag Doke
  • 863
  • 7
  • 17