SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 08-12-2018 06:36:43

StephanB
Member
Registered: 21-11-2018
Posts: 39

DOS Script will Count files in the XmlOut and output it to XML file

This Script will monitor the XmlOut folder to Count files in the XmlOut folder and output it to XML file for X-ServiceBroker to read the file from the DOS Script below, by adding it to X-ServiceBroker Schedules in the Initialisation.xml you can trigger it there.

@echo off
setlocal enabledelayedexpansion

REM Here I call the  GetUnixTime to get Unix Time to use it in the file name
call :GetUnixTime UNIX_TIME

ECHO ### Checking the number of files in XmlOut ###
set numFiles=0
for %%x in (C:\SXI\XPress\XmlOut\*.*) do (
  set file[!numFiles!]=%%~nfx
  set /a numFiles+=1
 )
REM ### Set Dest and Action 
set Dest=127.0.0.1
set ActionName=Test
set Provider=CountFile
ECHO ### Number of files found: %numFiles% 
REM  ### Set the XML Output attributes
echo ^<?xml version="1.0" encoding="UTF-8"?^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<XServiceBroker xmlns="http://www.sxi.co.za/XMLSchema"^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<XHeader^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<XPress^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<Destination^>%Dest%^</Destination^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^</XPress^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<XServiceBroker^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<ActionName^>%ActionName%^</ActionName^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<Provider^>%Provider%^</Provider^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^</XServiceBroker^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^</XHeader^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<Count^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^<TotalFiles^>%numFiles%^</TotalFiles^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^</Count^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
echo ^</XServiceBroker^> >> C:\SXI\XPress\XmlOut\X-ServiceBroker~%Provider%~%UNIX_TIME%.xml
endlocal
REM The GetUnixTim will be: 1341791426 seconds have elapsed since 1970-01-01 00:00:00
:GetUnixTime
setlocal enableextensions
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do (
    set %%x)
set /a z=(14-100%Month%%%100)/12, y=10000%Year%%%10000-z
set /a ut=y*365+y/4-y/100+y/400+(153*(100%Month%%%100+12*z-3)+2)/5+Day-719469
set /a ut=ut*86400+100%Hour%%%100*3600+100%Minute%%%100*60+100%Second%%%100
endlocal & set "%1=%ut%" & goto :EOF
EXIT 0
    <Schedules>
        <Schedule name="FileCountTriger">
            <AT>*/15 * * * *</AT>
            <Action>
                <Path>c:\sxi</Path>
                <Command>filecount.cmd</Command>
                <Arguments/>
            </Action>
        </Schedule>
    </Schedules>

Please add to this post if you have a better solution for us to use.

Last edited by StephanB (12-12-2018 06:13:58)

Offline

Board footer

Powered by FluxBB