dos - u've got to love it!!

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey all,

I'm writing a loop to do sereval tasks.

I help support over 1000 tills and Pc's. they sometimes have errors in which I need to rebuild 'POS' folders to get the till program to run.

This envoles

1, copying the enitia contents of a dir to a remote machine's c:\pos folder. (no problem there)
2, removing a few files from known loactions (no problem there)

(this is the tricky bit)
these POS folders have files called pos1.sts, pos1.err, pos1.tcf and pos1.cfg inside. The problem is they have these files for every till. ie, pos2, pos3, pos4, ect.....

I need to remove all .sts, .err, .tcf and .cfg files but the ones not affilated with the till in question (ie, on till 1 i'd need to remove all pos2.*, pos3.* ect...)

I could do this by makeing the user enter the till number, use that as a lable and for each lable do whats required for the till.

But i'd really like to just have one loop with values set for the different tills.

example;
Code:
goto %1           rem %1 being the till number you wish to run it for.

:till1

set /a till=pos1
set /a ip=%2.12   rem %2 being the stores network address
goto loop

:till2

set /a till=pos2
set /a ip=%2.13
goto loop

:loop
net use \\%2.11
copy \\%2.11\c$\master.pos\*.* c:\pos\*.*

del c:\%till%.lck
del c:\pos\%till%.sts
del c:\pos\%till%.err

This is the bit i'm unsure of. - i'd like to remove all pos*.sts, .err, .tcf, .cfg files but ones that start %till%.
goto fin


:fin
echo. Pos rebuild Complete  
exit

If i haven't explained this very well please ask.

any ideas??
 
do you need to copy the whole pos folder over to each machine and remove what you don't need? Or could you only copy over the files /needed/?

How does the IP's work. Can't have 1000 ips with the way you've done that. Is it 1000 PCS at once or what.
 
Last edited:
This gets the job done only for .sts though - probably could be a lot better (e.g. not use copy to temporary files).

Code:
set till=pos2
set till_num=%till:pos=%

set till_count=10

#rem copy to temp files

copy /Y pos%till_num%.sts pos%till_num%.sts.temp

FOR /L %%i IN (0,1,%till_count%) DO del pos%%i.sts

copy /Y pos%till_num%.sts.temp pos%till_num%.sts
del pos%till_num%.sts.temp
 
Try this:
Code:
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION


CALL :_SETUP
CALL :_GETIP
CALL :_TILLLOOP
CALL :_TIDYUP
GOTO:EOF


:_SETUP
ECHO SETUP
SET till_start=1
SET till_end=10
REM SET till_end=250
SET del_list=".sts .err .tcf .cfg"
GOTO:EOF

:_GETIP
ECHO GET IP
REM SET /P store_net_address=[ENTER IP]

SET store_net_address=123.123.123.
GOTO:EOF


:_TILLLOOP
FOR /L %%A IN (!till_start!,1,!till_end!) DO (
	SET till_no=%%A
	SET till=pos!till_no!
	SET /A tmp1=!till_no!+11
	SET ip=!store_net_address!!tmp1!
	CALL :_COPYDATA
	CALL :_PROCESSTILL
)
GOTO:EOF


:_COPYDATA
REM INSERT ALL DATA COPY STUFF
ECHO.WORKING ON TILL: !till_no!
ECHO.COPYING DATA....
ECHO till    = !till!
ECHO ip      = !ip!
ECHO till_no = !till_no!
GOTO:EOF

:_PROCESSTILL
ECHO.PROCESSING DATA....
FOR /L %%A IN (!till_start!,1,!till_end!) DO (
	FOR /F %%B IN (!del_list!) DO (
		IF %%A==!till_no! ( 
		ECHO NOT REMOVING
		) ELSE (
		ECHO DEL c:\pos%%A.lck
		ECHO DEL c:\pos\pos%%A%%B
		)
	)
)
GOTO:EOF


:_TIDYUP
REM PUT ANY CHECKS HERE AND TIDY UP ANYTHING 
ECHO FINISHING UP!
GOTO:EOF


:EOF
ECHO ALL DONE!

Just noticed, if you copy say data for tillls 1-100 over, but only process 1-50, the files for 51-100 will still be in each till c drive. Easy enough to change the thing though.

err, mistake fixed
 
Last edited:
swap this for an alternate method by deleting everything but the current till.

Code:
:PROCESSTILL
ECHO.PROCESSING DATA....
ECHO REN C:\!till!.lck C:\TMP_!till!.lck 
::rename current till files to TMP
FOR /F "usebackq" %%A IN (`DIR /B C:\pos\!till!*`) DO (
	ECHO REN C:\pos\%%A C:\pos\TMP_%%A
)
::delete all others
IF EXIST==C:\!till!*.lck DEL C:\!till!*.lck
IF EXIST==C:\pos\!till!* DEL C:\pos\!till!*

::Rename back from TMP
ECHO REN C:\TMP_!till!.lck C:\!till!.lck
FOR /F "usebackq" %%A IN (`DIR /B C:\pos\TMP_!till!*`) DO (
	SET tmpname=%%A
	SET newname=!tmpname:~4!
	ECHO REN C:\pos\%%A C:\pos\!newname!
)

GOTO:EOF
 
Back
Top Bottom