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 8907503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:55:58+00:00 2026-06-15T02:55:58+00:00

I have an issue with my batch file that incorporates a 10sec delay between

  • 0

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
  • 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-15T02:56:00+00:00Added an answer on June 15, 2026 at 2:56 am

    Assuming you don’t need to rename the files as you copy them, try

    %backupcmd% "!lastName!!baseExt!" "C:\Users\me\Desktop\Test Destination Folder\"
    

    Note: I find that the trailing \ negates the need for the /i switch.

    Edit: New strategy. Copy the base file first using the above command, then when you copy the final file it will overwrite it without prompting.

    for %%a in (*.*) do (
        if not defined baseName (
            rem Is first name of first set
            set baseName=%%~Na
            set baseExt=%%~Xa
            set lastname=%%~Na
            %backupcmd% "%%a" "C:\Users\me\Desktop\Test Destination Folder\"
        ) 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
                %backupcmd% "%%a" "C:\Users\me\Desktop\Test Destination Folder\"
            )
        )
    )
    
    • 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 on a Windows 2008 server that, when invoked from
I have a simple FOR loop inside of a batch file I'm creating that
I have a batch file that executes three Maven commands, one after the other.
I have a batch script, I think my issue has to do with parentheses
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
Share your ideas please! I have issue to check the folder and convert a
I have an issue while getting the file name with out extension from a
In vb.net, when writting an application, I want to access a batch file that
I am trying to understand a batch file that was sent to me in
I'm trying to make a batch file that makes a backup of the USB

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.