Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I've written a .bat to back-up some folders on my computer using xcopy. Is there any way to add a percentage to the process of each one? I won't bore with the whole script as it has a few menus and options but basically if this is the command:
xcopy /M /S /Q C:\pictures F:\backup\pictures
I'd like to display the process like this:
Backing up pictures: 38% Done
I've already searched google but haven't found what I am looking for. Not sure if it's even possible. Any ideas will be greatly appreciated. Thanks a lot in advance!

I don't think it's possible with straight xcopy and Command Scripts.
If you wanted to do your own directory walking and manually copy the files, then you could add percentage done logic, but I've stepped out of that particular arena.
If I have time tongiht, and no one posts their script, I'll throw together something so you're not left hanging.

This doesn't show the percentage, but rather a progress bar in a separate command shell window, while the files are copied in a minimized window.
@Echo Off
::Copy the first file.
Call :Pcopy "source 1" target1 /Options
::Copy the second file.
Call :Pcopy source2 "target 2" /Options
(Goto :EOF):Pcopy
Set Flagfile=%TEMP%.\%RANDOM%.tmp
If Exist %Flagfile% Del %Flagfile%
Start /Min Copy %* ^& Echo.^>%Flagfile% ^& Exit
(Set /P i=Copying %1) < NUL
:Pcopy1
If Exist %Flagfile% (Goto :EOF)
::Echo period w/o carriage return/line feed
(Set /P i=.) < NUL
::Wait one second (increase no. of ping requests
::in order to wait for a longer time)
Ping -n 2 127.0.0.1 > NUL
Goto Pcopy1

Thank you razor for your response. I was really trying to automate everything. My program works perfectly (most of the code I got from here by the way) but I just wanted the percentage for cosmetics. I am happy with what I have so far if I can add the percentage with out completely changing everything that would be great. But on the other hand I have no problem changing everything to get the desired result (if possible) But basically what I had in my first post was what I was trying to achieve. I can post my .bat file here (I think it's worthy) or I can e-mail it to you and see what you can do with it. Thank you again for the response and for your offer, any help is greatly appreciated but I am not in a rush. So when ever you get around to it I'll be right here.

Thanks Tony but I had already seen that, but it kinda gave me an idea. Here is what I came up with in, case anyone is trying to do the same thing. Remember that this is just for cosmetics and does not reflect the actual percent of completion. It just gives you something to look at while xcopy is doing its thing. It will start counting in a separate window when xcopy starts and will goto 100% and echo/do whatever when its finished.
::progress.bat
@ECHO OFF
set num=1
start /min yourxcopy.bat
ECHO Backing up files 1%%
CHOICE /T 2 /C yn /N /M "" /D y >> nul
:run
IF EXIST %temp%\whatever.txt (
set wait=CHOICE
set time=/T 1 /C yn /N /M "" /D y >> nul
) ELSE (
set wait=echo
set time=echo
)
cls
If %num%==100 goto done
set /a num=%num%+1
ECHO Backing up files %num%%%
%wait% %time% > nul
goto run
:doneand yourxcopy.bat would look like this
::yourxcopy.bat
@ECHO OFF
echo 123>>%temp%\whatever.txt
xcopy whateverto whatever
del /q %temp%\whatever.txt
exitI used choice for the delay rather than ping because I found that using ping uses too much resources, but if you need it to count faster ping with the -n 1 switch will do the trick. I hope this helps someone out in the future and hopefully some of the experts in here will be able to improve on it. Thanks again for the replies.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |