0

I'm making a program to organize some files into a "dictionary" that i can use, so instead of having to go through hundreds of folders and sub-forders, its all presented in a more clear way.

I have this function_sub that it's called every folder and that calls function_count that counts the amount of files and writes it to a temp file (Count.txt), for testing i have it echo out the variables %%A, %%B and %total% but for whatever reason when writing %total% it says "Echo is off" this means that it is not getting set, which souldn't happen since the type command that appears before writes the correct value.

:FUNCTION_SUB
for /d %%B IN (*) DO (
echo - %%B

pushd %%B
call :FUNCTION_COUNT
popd

type Count.txt
@set /p total=<Count.txt

echo ----------
echo %%A
echo %%B
echo %total%
echo ----------

)
goto :eof

Is there any limit to what the command @set is capable of doing?

I know there's a way of doing the same thing with a for loop but it can't happen here (or at least I wasn't able to do it) since it's already inside a loop, and I would like for all code to run in a single script.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    The problem with `total` not appearing to change is the #1 FAQ, 'delayed expansion` - there are many articles on this on SO - just use the `search` facility in the top bar. The quick answer is to use `call echo %%total%%` to output the value of a variable that has been changed within a code-block. – Magoo Apr 15 '18 at 23:52
  • Delayed expansion would help, _and would be the preferred method_; but you could use `Call Echo %%total%%` instead. – Compo Apr 15 '18 at 23:59
  • just to clarify: the command is `set`, not `@set`. `@` is a thing of it's own and means `don't repeat the command`. Usually used with `echo off` (which disables command repetition until end of the script (or `echo on`)) to suppress repetition of this very line too. – Stephan Apr 16 '18 at 06:42
  • Thanks for the sugestions, the use of `call echo %%total%%` worked. Thanks a lot guys. – megacrazyman Apr 16 '18 at 10:13

0 Answers0