I have an issue with my batch file that incorporates a 10sec delay between everytime it looks at a specified folder then CALLS a subroutine for naming convention:...batch that copies modified files in directory to another directory
I have modified the code according to Ken White which has been very helpful, however I have another issue that is further related to this batch, being that when the batch is ran and I do a test file update and save within the source directory, the batch asks me in the cmd console "to specify a file name or a directory name on the target" for EVERY file that it looks at. Since I want this to be automatically running in the background I don't want to have to have user input for it to run properly. Any help or suggestions would be very helpful.
Here is what I have currently:
@Echo Off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: variables
set drive=C:\Users\me\Desktop\Test Source Folder\
set backupcmd=xcopy /m /s /c /d /e /h /i /r /y
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
:_RevLoop
set basename=
for %%a in (*.*) do (
if not defined baseName (
rem Is first name of first set
set baseName=%%~Na
set baseExt=%%~Xa
set lastname=%%~Na
) else (
rem Check if this name begin with same baseName
set name=%%~Na
for %%b in (!baseName!) do set name=!name:*%%b=!
if "!name!" neq "%%~Na" (
rem Yes: Is next name of same set
set lastName=%%~Na
) else (
rem No: Is first name of next set: copy previous set and pass to next one
%backupcmd% "!lastName!!baseExt!" "C:\Users\me\Desktop\Test Destination Folder\!baseName!!baseExt!"
set baseName=%%~Na
set baseExt=%%~Xa
set lastName=%%~Na
)
)
)
rem Copy last set
%backupcmd% "!lastName!!baseExt!" "C:\Users\me\Desktop\Test Destination Folder\! baseName!!baseExt!"
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 JobBoss files...
::%backupcmd% "C:\Users\me\Desktop\Test Source Folder" "C:\Users\me\Desktop\Test Destination Folder\"
::CALL "C:\users\me\Desktop\Test Source Folder\Test.bat"
ECHO ___ Checking for new file revisions...
GOTO :_RevLoop
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