0

I am working on a program using batch where the program read root directories from a text file and count total number of Folders and Files in all th give root directories. The program is working as it should be but I want to display the output in a certain way.

This is how I want to display output

enter image description here

0 : OF : 6

The first value should change each time program finish counting in one root directory. I have written code for it but the output I am getting is this.

enter image description here

Here is code I have written to change it.

:textUpdate
echo !counter! : OF : %number%
GOTO :EOF

where counter is the current number of root directory and number is total number of directories found in the text file. Is there any way to display the output like the first one.

Ebad Ali
  • 600
  • 1
  • 6
  • 29
  • 1
    Where do u change the `number` variable – Monacraft Dec 24 '17 at 23:44
  • 1
    @Monacraft number variable is defined when I collect total number of directories in a given file and counter is incremented every time a directory files and folder count is finished. – Ebad Ali Dec 24 '17 at 23:49
  • 2
    When you say root directory count, do you mean you are performing the routine on each volume/partition? _(There is only one root directory in each)_. Either way, if you're doing a number `x` of `y` you first need to count them all so that you know the value of `y`. What method are you using for that? _Please provide the code..._ – Compo Dec 25 '17 at 02:08
  • Please note that https://stackoverflow.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). – DavidPostill Dec 25 '17 at 09:34
  • Possible duplicate of [How to code a spinner for waiting processes in a Batch file?](https://stackoverflow.com/questions/368041/how-to-code-a-spinner-for-waiting-processes-in-a-batch-file) – phuclv Dec 25 '17 at 10:20

1 Answers1

1

you can abuse set /p to write to screen. It doens't append a line feed. You also need a Carriage Return to go back to the beginning of the line to overwrite the old output:

@echo off
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
for /l %%n in (1,1,6) do (
    set /P "=Count %%n of 6!CR!" <nul
    timeout 1 >nul
)

The first for /f loop is just to get a CR (Carriage Return). You have to use delayed expansion to be able to use it (%CR% does not work).

Stephan
  • 53,940
  • 10
  • 58
  • 91