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

  • Home
  • SEARCH
  • 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 9280125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:47:45+00:00 2026-06-18T17:47:45+00:00

First question here. I’ve used batch files for automating a lot of action but

  • 0

First question here. I’ve used batch files for automating a lot of action but this one is getting really difficult.

Imagine I have a folder (lets call it ‘ProjectFolder’) and I have some folders inside this project folder (lets call them ‘data’, ‘tools, ‘trash’) and each of these folders have files.
What I want is to create inside the ‘ProjectFolder’ a ‘backup’ folder and inside this one a folder called ‘v001_date_time_user’ and copy folders ‘data’ and ‘tools’ inside this folder.
Then I run this script again to make a new version and it creates ‘v002_date_time_user’ and copies the same ‘data’ and ‘tools’ folders and files again.

What I can do now is create a folder called ‘v_date_time_user’ inside the ‘backup’ folder but I have no idea how to create the version part with 3 digits.

This is my code for now:

@echo off & setlocal enableextensions

:: variables
set dateNtime="[%date:~6,6%-%date:~3,2%-%date:~0,2%]_[%time:~0,2%-%time:~3,2%]"
set backup="backup"

set /A version=000

set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

:: check for existence of [backup]
:: if [backup] doesn't exist, create it
if not exist "%backup%\" (
  echo folder "%backup%" not found
  echo creating folder "%backup%"
  md "%backup%" 
  )

:: create version folder with version number_date_hour_user
md "%backup%\v%version%_%dateNtime%_[%USERNAME%]"

:: copy older version into newer version
xcopy "data" "%backup%\v%version%_%dateNtime%_[%USERNAME%]\data" /E /C /I /H /Q 
xcopy "tools" "%backup%\v%version%_%dateNtime%_[%USERNAME%]\tools" /E /C /I /H /Q 

can anyone help?
thanks
Luís

  • 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-18T17:47:47+00:00Added an answer on June 18, 2026 at 5:47 pm

    There are a couple of ways I can think of. You could loop through every folder beginning with a v and a number, and count them. Then if you’re starting with 000 then the number of matches will be your next number.

    @echo off
    setlocal enabledelayedexpansion
    :: if you're starting with 001 rather than 000, then set count=1 instead of 0 here.
    set count=0
    pushd "path\to\ProjectFolder\backup"
    for /f %%I in ('dir /b v* ^| findstr "^v[0-9][0-9][0-9]"') do set /a count=!count!+1
    popd
    set count=00%count%
    set count=%count:~-3%
    

    Then %count% will be your next number.

    Another way would be to loop through dir /b /o:n (alphabetic sorting) and capture the last directory name, presumably v### with the highest number. Then grab the first four characters of that capture and chop off the v.

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

Sidebar

Related Questions

this is my first question here, but i hope i will provide all the
This is my first question here but I'm sure there are many more to
My first question here. The question is similar to this one: PHP: Retrying a
This is my first question here :) I really need help with some servers
my first question here. And I'm sure it's an easy one, but I can't
This is my first question here in stackoverflow. This website really helped me a
this is my first question here so be gentle ! recently i try to
this is my first question here :) I know that I should not check
This is my first question here so try to make my best so you
Ok, I need help. This is my first question here. Background: I am working

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.