1.

Solve : Set dir contence as seperate strings?

Answer»

So for my robotics team I am making a program that will record match data on each team. I am RUNNING into a problem when I want to desplay all the teams scores at once. I am writing the scores in their own text file in c:\...\teams\%team number%\scr.txt and c:\...\teams\%team number%\ascr.txt. Currently I am using a loop to run through all the possable team numbers (1-5000) and using
Code: [Select]echo off
set /p color =<clr.txt
color %color%
title =View scores
cls
cd..
cd Teams
set teamnum=0
:loop
if not exist %teamnum% goto skip
cd %teamnum%
set /p ascr=< ascr.txt
set /p scr=< scr.txt
echo %teamnum%
echo.
echo Total        %scr%
echo Adverage %ascr%
echo ---------------------------------------------------
cd ..
:skip
set /a a=%teamnum%+1
set teamnum=%a%
if "%teamnum%" =="5001" goto end
goto loop
:end
echo.
echo.
pause
cls
cd ..
cd system
call home.bat

This takes somewhere between 5-10 minutes each time I run it, and I was wondering if there was a way that I could set the either use the %var:~#,#% or set %var#%=< dir (set each folder to a string) to SHORTEN the waiting time. Thank you so much!

EDIT: running on windows 7, but would like it to run on any windows OS.
also looking for a .bat -> .exe converter to get around this if it becomes a problem modifying it to work.
EDIT2: fixed the code (had wrong version up)It seems to me you need to sit down and really think about what needs to be done. Get the storage scheme right and worry about the code later. Do you really have 5000 teams? Or some smaller number? If you have more than a small number the scores are going to start scrolling off the screen, since showing each team's score uses 4 LINES of screen space. Why can't you have just one text file to hold all the data? Using separate folders like this is a very inefficient method, and is bound to be slow.

What does system\home.bat do?

Using your separate folders method can be speeded up a bit.

You seem to have one ascr.txt and one scr.txt in each team's folder, these files having one line which is a number?

See comments.

Code: [Select]echo off
REM is there really a Team zero?
set teamnum=0

set limit=5000

REM We will time how long it takes

set stime=%date% %time%

:loop

REM No need to keep going in and out of the folders
set foldername=Teams\%teamnum%
if not exist %foldername% goto skip

set /p ascr=< %foldername%\ascr.txt
set /p scr=<  %foldername%\scr.txt

REM I put it all on one line for neatness
echo Team %teamnum%: Total: %scr% Average: %ascr%

:skip

REM You don't need 2 variables here
REM set /a a=%teamnum%+1
REM set teamnum=%a%

REM You can do this
REM set /a teamnum=%teamnum%+1
REM or this
set /a teamnum+=1

REM Another way to compare numbers
REM See IF /? for these details
REM EQU - equal
REM NEQ - not equal
REM LSS - less than
REM LEQ - less than or equal
REM GTR - greater than
REM GEQ - greater than or equal

if %teamnum% GTR %limit% goto end

goto loop

:end

REM How long did we take?
set etime=%date% %time%
echo %limit% start %stime%
echo %limit% end   %etime%

I created 5000 (!) directories in a Teams folder and put an ascr.txt and a scr.txt containing random values in each one and then ran the above code and it took just over 35 seconds to read and display all the scores. Of course the earlier scores scrolled off the screen so I just copied the last 10 lines to show you.

You took 5 to 10 minutes?? What kind of machine?

Code: [Select]Team 4990: Total: 10  Average: 5
Team 4991: Total: 36  Average: 19
Team 4992: Total: 6  Average: 40
Team 4993: Total: 73  Average: 71
Team 4994: Total: 91  Average: 69
Team 4995: Total: 55  Average: 63
Team 4996: Total: 47  Average: 17
Team 4997: Total: 81  Average: 37
Team 4998: Total: 82  Average: 24
Team 4999: Total: 46  Average: 18
Team 5000: Total: 96  Average: 45
5000 start 04/03/2012 12:13:55.81
5000 end   04/03/2012 12:14:30.36

Quote from: Salmon Trout on March 04, 2012, 04:02:54 AM

It seems to me you need to sit down and really think about what needs to be done. Get the storage scheme right and worry about the code later. Do you really have 5000 teams? Or some smaller number? If you have more than a small number the scores are going to start scrolling off the screen, since showing each team's score uses 4 lines of screen space. Why can't you have just one text file to hold all the data? Using separate folders like this is a very inefficient method, and is bound to be slow.

What does system\home.bat do?

1) There are about 40 teams in each competition with numbers ranging from 0-5000.
2) home.bat is a menu page
3) Thank you for the one line recommendation.
4) I have to use 2 diffrent files for scr and ascr for the set /p VAR=< FILENAME command

Quote from: Salmon Trout on March 04, 2012, 05:24:32 AM
Using your separate folders method can be speeded up a bit.

You seem to have one ascr.txt and one scr.txt in each team's folder, these files having one line which is a number?

See comments.

Code: [Select]echo off
REM is there really a Team zero?
set teamnum=0

set limit=5000

REM We will time how long it takes

set stime=%date% %time%

:loop

REM No need to keep going in and out of the folders
set foldername=Teams\%teamnum%
if not exist %foldername% goto skip

set /p ascr=< %foldername%\ascr.txt
set /p scr=<  %foldername%\scr.txt

REM I put it all on one line for neatness
echo Team %teamnum%: Total: %scr% Average: %ascr%

:skip

REM You don't need 2 variables here
REM set /a a=%teamnum%+1
REM set teamnum=%a%

REM You can do this
REM set /a teamnum=%teamnum%+1
REM or this
set /a teamnum+=1

REM Another way to compare numbers
REM See IF /? for these details
REM EQU - equal
REM NEQ - not equal
REM LSS - less than
REM LEQ - less than or equal
REM GTR - greater than
REM GEQ - greater than or equal

if %teamnum% GTR %limit% goto end

goto loop

:end

REM How long did we take?
set etime=%date% %time%
echo %limit% start %stime%
echo %limit% end   %etime%

I created 5000 (!) directories in a Teams folder and put an ascr.txt and a scr.txt containing random values in each one and then ran the above code and it took just over 35 seconds to read and display all the scores. Of course the earlier scores scrolled off the screen so I just copied the last 10 lines to show you.

You took 5 to 10 minutes?? What kind of machine?

Code: [Select]Team 4990: Total: 10  Average: 5
Team 4991: Total: 36  Average: 19
Team 4992: Total: 6  Average: 40
Team 4993: Total: 73  Average: 71
Team 4994: Total: 91  Average: 69
Team 4995: Total: 55  Average: 63
Team 4996: Total: 47  Average: 17
Team 4997: Total: 81  Average: 37
Team 4998: Total: 82  Average: 24
Team 4999: Total: 46  Average: 18
Team 5000: Total: 96  Average: 45
5000 start 04/03/2012 12:13:55.81
5000 end   04/03/2012 12:14:30.36



Thanks for the respond, I like the set /a VAR+=1 that will HELP alot.
1) I like the one line suggestion a lot.
2) No there is not a team 0  thank you for point that out
3) I'm running it on my laptop (slow D:)


I did end up getting it to work last night. Thank you for your help! I'm ganna go through and check if Salmon Trout's runs faster, but here is what I did:
Code: [Select]echo off
set /p color=< clr.ghx
color %color%
Title =GHX - View
cls

start v1.exe
start v2.exe
start V3.exe
start v4.exe
start v5.exe

set a=0
set b=0
set c=0
set d=0
set e=0

cd ..
cd teams
cd %date:~10,4%
:wait
cls

if exist vc1.ghx set a=1
if exist vc2.ghx set b=1
if exist vc3.ghx set c=1
if exist vc4.ghx set d=1
if exist vc5.ghx set e=1
set /a ttl=%a%+%b%+%c%+%d%+%e%
if "%ttl%" =="0" echo 0%
if "%ttl%" =="1" echo 20%
if "%ttl%" =="2" echo 40%
if "%ttl%" =="3" echo 60%
if "%ttl%" =="4" echo 80%
if "%ttl%" =="5" echo 100%
if "%a%" =="1" if "%b%" =="1" if "%c%" =="1" if "%d%" =="1" if "%e%" =="1" goto show
REM the ping is to stop the flashing numbers
ping 127.0.0.1 >nul
goto wait

:show
cls
if exist v1.ghx type v1.ghx
if exist v2.ghx type v2.ghx
if exist v3.ghx type v3.ghx
if exist v4.ghx type v4.ghx
if exist v5.ghx type v5.ghx

if exist v1.ghx set v1=< v1.ghx
if exist v1.ghx set v2=< v2.ghx
if exist v1.ghx set v3=< v3.ghx
if exist v1.ghx set v4=< v4.ghx
if exist v1.ghx set v5=< v5.ghx
set vcom=%v1%%v2%%v3%%v4%%v5%
if "%vcom%" =="" echo No teams indexed



echo.
if exist v1.ghx del v1.ghx
if exist v2.ghx del v2.ghx
if exist v3.ghx del v3.ghx
if exist v4.ghx del v4.ghx
if exist v5.ghx del v5.ghx

if exist vc1.ghx del vc1.ghx
if exist vc2.ghx del vc2.ghx
if exist vc3.ghx del vc3.ghx
if exist vc4.ghx del vc4.ghx
if exist vc5.ghx del vc5.ghx
set /p nouse=Press Enter
cd ..
cd ..
cd system
call home.bat I used a bat->exe compiler to make it run without opening a window (that's why i used a exe)
here is v1.exe
Code: [Select]
echo off
cd ..
cd teams
cd %date:~10,4%
set a=1
:loop
if not exist %a% goto loop.break
cd %a%
set /p scr=< scr.ghx
set /p ascr=< scr.ghx
cd ..
echo %a% >>v1.ghx
echo. >>v1.ghx
echo Total %scr%>>v1
echo Average %ascr% >>v1
:loop.break
set /a b=%a%+1
set a=%b%
if "%a%" =="1001" goto exit
goto loop
:exit
echo 1 >>vc1.ghx
exit
here is v2.exe
Code: [Select]
echo off
cd ..
cd teams
cd %date:~10,4%
set a=1001
:loop
if not exist %a% goto loop.break
cd %a%
set /p scr=< scr.ghx
set /p ascr=< scr.ghx
cd ..
echo %a% >>v2.ghx
echo. >>v2.ghx
echo Total %scr%>>v2.ghx
echo Average %ascr% >>v2.ghx
:loop.break
set /a b=%a%+1
set a=%b%
if "%a%" =="2001" goto exit
goto loop
:exit
echo 1 >>vc2.ghx
exit
the rest (v3-v5.exe) follow the pattern until teams 0-5000 are covered

Any comments\suggestions?

BTW: can you open a 'SFX module' exe file without winRAR?

Thanks again for the help!

EDIT: ran Salmon Trout's code, and I think it's a problem with my computer because it took 4 min 
Code: [Select]5000 start Sun 03/04/2012 13:41:29.76
5000 end  Sun 03/04/2012 13:44:41.86
delete?


Discussion

No Comment Found