Page 1 of 1

Increment Variable

Posted: 18 Jun 2008 18:10
by jem00
Hey guys,

Is it possible to increment the value of a variable during an xcopy?

For example:

Code: Select all

set /a counter = 1
xcopy /d /e/ h/ y c:\folder c:\anotherFolder



There are 100 files in the folder.
For the above example is it possible to increment the value of counter after one file has copied? so 1 out of 100?

Any advice is welcome

Re

Posted: 30 Jun 2008 03:29
by Thebetr1
You cant.

you cant use a command while you are using another command.

just use dir "blabla" >> file.txt and count the number of lines.



if anyone knows a way to do this let me know :D

Posted: 03 Jul 2008 22:41
by DosItHelp
jem00,

The /L option of XCOPY lists the files that would be copied. You can iterate this list using a FOR command and copy and count each item as you go, like this:

Code: Select all

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set "sourcedir=c:\folder"
set "targetdir=c:\anotherFolder"
set xcopyoptions=/d /e /h /y

rem -- count the files, show progress in window title
set /a cnt=0
for /f "tokens=*" %%A in ('"xcopy %xcopyoptions% /L "%sourcedir%" "%targetdir%""') do (
    set /a cnt+=1
    title counting files to copy: !cnt!
)

rem -- copy the files, show progress in window title
for /f "tokens=*" %%A in ('"xcopy %xcopyoptions% /L "%sourcedir%" "%targetdir%""') do (
    title Copying files, remaining: !cnt!
    echo. -- xcopy %xcopyoptions% "%%A" "%targetdir%"
    set /a cnt-=1
)
title done!



DosItHelp? :wink: