1.

Solve : XCOPY ---- Progress Display ... ??

Answer» Input:
Code: [Select]<nul

Output:
Code: [Select]>nul

Quote
Ok ... now that I've said this I will read the code and let you know what I think.

I gotta talk to Nathan about that raise.

PS. The code will not work if you insist on using XCOPY. You're not using any switches that are unique to XCOPY, so COPY is actually a better choice.
Quote from: Sidewinder on January 23, 2009, 03:48:28 PM

PS. The code will not work if you insist on using XCOPY. You're not using any switches that are unique to XCOPY, so COPY is actually a better choice.


Didn't think copy worked correctly over network drives? Maybe it would work by using Pushd, this is a new command I found, from what i have read creates a temporary drive until you popd it off ... Completed product with COPY for now ... going to play with xcopy later ... Why do you say xcopy won't work? Thank you very much for all your effort put forth into this, a raise would be a wonderful thing.

Code: [Select] @echo off
set wkdir=%cd%\workdir
set dest=%cd%\dest

set perc=0

setlocal enabledelayedexpansion

if not exist "%wkdir%" md "%wkdir%"

pushd %wkdir%

:: Get Number of Files in Dir

for /f "tokens=1*" %%i in ('dir /a:-d ^| find /i "file(s)"') do set count=%%i

set storcount=%count%


Title 0%% Done

echo Start Copy Operation
Echo.
Echo The numbers printed to screen represent the number of files left to copy
Echo.
:: Copy Files; Show Progress

For /f "delims=" %%a in ('dir /b /a:-d /o:-d') do (

<nul call set/p z= !count!
copy "%wkdir%\%%a" "%dest%\%%a" > nul
rem >nul ping localhost -n 2

set /a count-=1


set /a perc+=1


set /a p=(!perc!*100^)/%storcount% >>log.log


title !p!%% Done
)

popd
echo.
echo End Copy Operation & pause >nulQuote
Why do you say xcopy won't work?

I may have misspoke. There goes my raise! You're only feeding one file at a time to XCOPY so I'm guessing COPY and XCOPY will work same.

Quote
Didn't think copy worked correctly over network drives?

Where did you here this? I've never had any problems with copy over a network using either UNC notation or mapping the drive. My only experience with PUSHD and the flipside POPD as been to put directory names on the stack for future retrieval. Learn something new everyday. Sidewinder, I was hoping I could pick your brain one more time. I added some code and seem to have broken what I had, thought I found my mistake, but the batch file is still crashing. Here is the code ....


Part of what I added ... I like the output to the screen, but as I get to double/single digits the display starts to look look off. I wanted to count the number of CHAR in the Count VAR to determine if it was 1, 2, or 3 char long then output accordingly by adding a leading zero to the number when it outputted to the console.


I used this code before to do a count, but never in a For loop ... maybe that is my problem. I found a couple mistakes so maybe there is something I am missing. Thanks again for your help. At this rate I might have to pay your raise.

Code: [Select] :LOOP_0
IF "!counter!"=="" GOTO :RESULT
SET /a strgCount+=1
SET counter=%counter:~1%
GOTO :LOOP_0

:RESULT
The whole thing

Code: [Select]ECHO on
set wkdir=%cd%\workdir
set dest=%cd%\dest

set perc=0
set counter=0
SET strgCount=0

setlocal enabledelayedexpansion

if not exist "%wkdir%" md "%wkdir%"



Rem Get Number of Files in Dir

pushd %wkdir%
for /f "tokens=1*" %%i in ('dir /a:-d ^| find /i "file(s)"') do set count=%%i

Rem Store number of files for Percentage completion tracking
set storcount=%count%
Title 0%% Done

ECHO Start Copy Operation
ECHO.
ECHO The numbers printed to screen represent the number of files left to copy
ECHO.

REM Copy Files Show Progress


For /f "delims=" %%a in ('dir /b /a:-d /o:-d') do (

set counter=!count!
SET strgCount=0

:LOOP_0
IF "!counter!"=="" GOTO :RESULT
SET /a strgCount+=1
SET counter=%counter:~1%
GOTO :LOOP_0

:RESULT


if "!strgcount!"=="3" Goto pass1
Goto check1
:pass1
<nul call set/p z= !count! & goto copypro
:Check1
if "!strgcount!"=="2" Goto pass2
Goto check2
:pass2
<nul call set/p z= 0!count! & goto copypro
:Check2
if "!strgcount!"=="1" Goto pass3
Goto check3
:pass3
<nul call set/p z= 00!count! & goto copypro

:Check3
:copypro
copy "%wkdir%\%%a" "%dest%\%%a" > nul

set /a count-=1
set /a perc+=1

Rem Changes title to ^%Percentage
set /a p=(!perc!*100^)/%storcount%

title !p!%% Done
)

popd

ECHO.
ECHO End Copy Operation & pause >nulQuote
At this rate I might have to pay your raise.

You can't afford me. Either can Nathan, but I haven't told him yet.

Quote
Part of what I added ... I like the output to the screen, but as I get to double/single digits the display starts to look look off. I wanted to count the number of CHAR in the Count VAR to determine if it was 1, 2, or 3 char long then output accordingly by adding a leading zero to the number when it outputted to the console

What happens if the last count on the line wraps to the NEXT line?

This is some generic code I found. Works for three digits. I'll let you incorporate it into your code.

Code: [Select]@echo off
setlocal
:loop
call set chr=%%count:~%len%, 8192%%
if "%chr%"=="" goto exit
set /a len+=1
goto loop

:exit
if %len% EQU 1 set count=00%count%
if %len% EQU 2 set count=0%count%
echo %count%

Good luck.

You can remove the setlocal statement. I used it for testing purposes. The 8192 is the max size of the environment on a XP machine. You can reduce this in keeping with your needs. Five would be a good choice for future expansion.Question ... does doing a loop without the call procedure throw yourself out of the normal for loop operation ... is that what I was doing wrong? This is pretty good.

Just a thought - How can this be made to work for recursive copying. What if wkdir has subdirectories in it?

I am sorry to put in a question of my own within this conversation. If you want me to open a new topic, would be glad to do that too. However I thought since this is an active topic, I will just post my question here.

Notice I didn't try to incorporate the snippet into your code. I was afraid the whole thing would fall apart.

Why not USE the call instruction to transfer control to an internal subroutine? You can format the count immediately prior to writing on the console?

Quote
Question ... does doing a loop without the call procedure throw yourself out of the normal for loop operation

I think the fact of a :label within the for loop is creating unpredictable results. I'm not certain how the interpreter keeps track of the return addresses.

How did a seemingly simple copy operation turn into such a Rube Goldberg contraption? Batch code is NOT a programming language.



If the KISS recruiter needs applicants, he should LURK in the DOS alley.

@hiteshsavla
Quote
Just a thought - How can this be made to work for recursive copying. What if wkdir has subdirectories in it?
If this refers to your other post, don't even think it. Quote from: Sidewinder on January 26, 2009, 03:12:29 PM
Notice I didn't try to incorporate the snippet into your code. I was afraid the whole thing would fall apart.

Your right, it fell apart ... I guess I have never run into trying to do something in a FOR loop before. ... I guess I confused how to continue then. I guess the whole effort is just make the display on the screen more in line, as the numbers get small they start to get out of line and I no longer have pretty columns ... Love the bit of code Code: [Select]<nul call set /p z= !count! much better then echo

My problem is by calling a routine I end up getting it to work again, but get a message that echos 'The system cannot find the batch label specified -'

This bit of code was purely to make the display nicer ...
Code: [Select] if %len% EQU 1 set count=00%count%
if %len% EQU 2 set count=0%count%
Quote


How did a seemingly simple copy operation turn into such a Rube Goldberg contraption? Batch code is NOT a programming language.


Your right it isn't a batch language, but i'm amazed everyday I learn something new that it can do , thanks for all your help.


Discussion

No Comment Found