Rainow
Rainow

Reputation: 41

Copy a folder and its content several times, then rename them

I'm looking for a simple batch script for windows 7 to copy a folder and its content from a destination, and paste it to another destination, x times, with incremental names.

Example:

Given a folder C:\Folder. I want to duplicate it into this folder: C:\Destination 7 times with diffenrent names, so the outcome looks like this (inside C:\Destination):

Copy1

Copy2

Copy3

.

.

Copy7

Thanks in advance!

Upvotes: 3

Views: 6367

Answers (2)

user5498372
user5498372

Reputation: 11

This is what you need: Windows Batch Script for Incremental Backup

@echo off
set source=c:\temp\test\1
set dest_path=c:\temp\test\2\
pushd %dest_path%
setlocal enableDelayedExpansion
set "dest_folder_name=Backup"
set "n=0"
for /f "delims=" %%F in 
(
   '2^>nul dir /b /ad "%dest_folder_name%*."^|findstr /xri "%dest_folder_name%[0-9]*"'
) 
do (
  set "name=%%F"
  set "name=!name:*%dest_folder_name%=!"
  if !name! gtr !n! set "n=!name!"
)
set /a n+=1
set final_destination="%dest_path%%dest_folder_name%%n%"
md %final_destination%
robocopy %source% %final_destination% /E /R:3 /W:10 /FFT /NP /NDL
popd
@echo on

Upvotes: 1

David Ruhmann
David Ruhmann

Reputation: 11367

for /l %%A in (1,1,7) do @xcopy "C:\Folder" "C:\Destination\Copy%%A" /i

See for /? and xcopy /? for all the options and help.


To run this on the command line make sure to use %A instead of %%A.

Use %variable to carry out for from the command prompt. Use %%variable to carry out the for command within a batch file. Variables are case-sensitive and must be represented with an alpha value, such as %A, %B, or %C.

Upvotes: 6

Related Questions