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.

5
  • 1
    Where do u change the number variable Commented Dec 24, 2017 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. Commented Dec 24, 2017 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... Commented Dec 25, 2017 at 2:08
  • Please note that 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?. Commented Dec 25, 2017 at 9:34
  • Possible duplicate of How to code a spinner for waiting processes in a Batch file? Commented Dec 25, 2017 at 10:20

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.