Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:25:02+00:00 2026-06-13T23:25:02+00:00

I have a batch file that will check for updates within a directory then

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:25:04+00:00Added an answer on June 13, 2026 at 11:25 pm

    The Batch program below assume that newer files have revision numbers or letters in ascending alphabeticall order, so the last listed file is the newest one. This way, the program identify a set of files that begin with the same name, and copy the last one of the set with the name of the first one in the set.

    @echo off
    setlocal EnableDelayedExpansion
    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
             ECHO copy "!lastName!!baseExt!" "C:\dest\dir\!baseName!!baseExt!"
             set baseName=%%~Na
             set baseExt=%%~Xa
             set lastName=%%~Na
          )
       )      
    )
    rem Copy last set
    ECHO copy "!lastName!!baseExt!" "C:\dest\dir\!baseName!!baseExt!"
    

    Test the program and remove ECHO commands if it works as you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a batch file that will detect if the user has the .Net
I have a Windows batch file that processes all the files in a given
I have several batch files that I call from a parent batch file. I
I have a batch file that runs ant and then copies one of the
I want to have a batch file that will delete all the folders and
I'm working on a Windows batch file that will bcp three text files into
I have a batch file that needs to be passed a parameter that will
I want to create a batch file that will sort the files(based on created
I want to make a batch file that will search for all files in
I have a batch file that requires the user to enter a file path.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.