I have a batch file that will check for updates within a directory then copy any new files or recently modified files to the other selected directory, however I'm unsure how to check the source directory for say two files that have just a revision number or letter difference: example.pdf and exampleA.pdf. I need to compare the files somehow by both string and date modified. So if the source directory has a new file that's been saved as exampleB.pdf, I need the batch to copy that file into the destination directory as example.pdf instead of the new filename. I want the copied file to have the core filename if you will, being just example.pdf
Any help would be much appreciated.
Thanks
@Echo Off
:: variables
set drive=G:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
set revchk=if
Set _Delay=10
Set _Monitor=C:\Users\me\Desktop\Test Source Folder
Set _Base=%temp%\BaselineState.dir
Set _Chck=%temp%\ChkState.dir
Set _OS=6
Ver|Findstr /I /C:"Version 5">Nul
If %Errorlevel%==0 Set _OS=5 & Set /A _Delay=_Delay*1000
:_StartMon
Call :_SetBaseline "%_Base%" "%_Monitor%"
:_MonLoop
If %_OS%==5 (Ping 1.0.0.0 -n 1 -w %_Delay%>Nul) Else Timeout %_Delay%>Nul
Call :_SetBaseline "%_Chck%" "%_Monitor%"
FC /A /L "%_Base%" "%_Chck%">Nul
If %ErrorLevel%==0 Goto _MonLoop
echo ### Backing up...
%backupcmd% "C:\Users\me\Desktop\Test Source Folder" "C:\Users\me\Desktop\Test Destination Folder"
echo ### Checking for new file revisions...
Echo.Backup Complete!
Goto :_StartMon
:::::::::::::::::::::::::::::::::::::::::::::::::::
:: Subroutine
:::::::::::::::::::::::::::::::::::::::::::::::::::
:_SetBaseline
If Exist "%temp%\tempfmstate.dir" Del "%temp%\tempfmstate.dir"
For /F "Tokens=* Delims=" %%I In ('Dir /S "%~2"') Do (
Set _Last=%%I
>>"%temp%\tempfmstate.dir" Echo.%%I
)
>"%~1" Findstr /V /C:"%_Last%" "%temp%\tempfmstate.dir"
Goto :EOF