I'm almost done, but now stucked in duplicate check.
Posted: 19 Nov 2011 07:05
Hi All,
I'm creating a batch file that will collate data, merge, create xml and zip. That's the routine of my code and it creates a summary report in of the processed files. Now, I'm stucked with duplicate check, what I'm trying to do is to check the files to be processed if it is in the summary report, the program will not processed it and will create a duplicate report.
Here my code:
Sorry if it's not professionally written, I'm not pro on this, still learning, but if you can improve it, thanks in advance. And also, if you notice in my code, I'm calling the dos commands in full path, it's because I've encountered weird error: 'dos command' is not recognized as an internal or external command, operable program or batch file.
Here my input files: http://www.mediafire.com/?nwsg240s0xtb6pc
Zip program: http://www.mediafire.com/?i695tgx9vlso3t9
my folder structure: D:\TEST\current date here eg.11-19-2011
Thanks in advance.
I'm creating a batch file that will collate data, merge, create xml and zip. That's the routine of my code and it creates a summary report in of the processed files. Now, I'm stucked with duplicate check, what I'm trying to do is to check the files to be processed if it is in the summary report, the program will not processed it and will create a duplicate report.
Here my code:
Code: Select all
@echo off
color 1F
mode con: cols=45 lines=14
title PEU v0.1
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::start day of the year
set "DateStr=%~2"&if "%~2"=="" set "DateStr=%date%"
for /f "skip=1 tokens=2-4 delims=(-)" %%r in ('"echo.|date"') do (
for /f "tokens=1-3 delims=/.- " %%R in ("%DateStr:* =%") do (
set %%r=%%R&set %%s=%%S&set %%t=%%T))
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
set /a JD=dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
set /a "yy=10000%yy% %%10000,mm=1,dd=1"
set /a JD-=-1+dd-32075+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4
IF "%~1" NEQ "" (SET %~1=%JD%)
::end day of the year
set "rdate=%date:~-10%
set "petsa=%rdate:/=-%"
set "county="
set "path=D:\TEST\%petsa%"
rem set "path=\\SLAGS1301\STORAGE11\TNT\PROD\PCSCCCSPOST-PCOF\PROCESS\[07] FOR RELEASE\%petsa%"
set "num=1010"
set "num2=0"
:menu
cls
echo.
echo( -------------------------------------------
echo( PABO EASY UTILITY V0.1 Beta
echo( -------------------------------------------
echo( [1] AT - Austria
echo( [2] NL - Netherlands
echo( [3] DE - Germany
echo( [4] BE02 - Belgium Flanders
echo( [5] BE04 - Belgium Wallone
echo( -------------------------------------------
echo.
set /p "moption=- What do you want to process?>
echo("%moption%"|C:\Windows\System32\findstr /vrxc:"\"[1-5]\"" >nul &&goto menu
if "%moption%"=="1" call :AT
if "%moption%"=="2" call :NL
if "%moption%"=="3" call :DE
if "%moption%"=="4" call :BE02
if "%moption%"=="5" call :BE04
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:coll
cls
echo.
echo( Done copying files...
echo.
set /p "collate=-Proceed collating files? [Y/N]: "
echo("%collate%"|C:\Windows\System32\findstr /vrxc:"\"[ny]\"" >nul &&goto coll
if /i "%collate%"=="y" call :koleyt
if /i "%collate%"=="n" exit /b
echo.
echo.
:merg
cls
echo( Done collating...
echo.
set /p "merge=-Proceed to xml and zipping? [Y/N]: "
echo("%merge%"|C:\Windows\System32\findstr /vrxc:"\"[ny]\"" >nul &&goto merg
if /i "%merge%"=="y" call :finout
if /i "%merge%"=="n" exit /b
goto :eof
:AT
if not exist "AT" md "AT"
C:\Windows\System32\xcopy /s /y "%path%\AT" "AT"
set "county=AT"
goto :eof
:NL
if not exist "NL" md "NL"
C:\Windows\System32\xcopy /s /y "%path%\NL" "NL"
set "county=NL"
goto :eof
:DE
if not exist "DE" md "DE"
C:\Windows\System32\xcopy /s /y "%path%\DE" "DE"
set "county=DE"
goto :eof
:BE02
if not exist "BE02" md "BE02"
C:\Windows\System32\xcopy /s /y "%path%\BE02" "BE02"
set "county=BE-Flanders"
goto :eof
:BE04
if not exist "BE04" md "BE04"
C:\Windows\System32\xcopy /s /y "%path%\BE04" "BE04"
set "county=BE04-Wallone"
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:koleyt
cls
setlocal enabledelayedexpansion
set "dats=!date:~-10!
set "dat=!dats:~0,5!"
set "petsa=!dat:/=!"
set "base=PABO"
if exist "SummaryReport_!petsa!.csv" (
for /f "tokens=3" %%H in ('C:\Windows\System32\find /c ".txt" "SummaryReport_!petsa!.csv"') do (
set /a "num2+=1"
set /a "num2+=%%H"
)
) else (
set /a "num2+=1"
)
set /a "num2+=1000"
for /f "tokens=1 delims=" %%a in ('dir /b /on "*."') do (
set "main=%%a"
for /f "tokens=1 delims=" %%b in ('dir /s /b "!main!\*.tif?"') do (
if not exist "!main!\2011!JD!" md "!main!\2011!JD!"
move "%%b" "!main!\2011!JD!"
)
for /f "tokens=1 delims=" %%c in ('dir /s /b "!main!\*.txt"') do (
move "%%c" "!main!\"
)
for /f "tokens=1 delims=" %%d in ('dir /b "!main!\p*."') do (
rd /s /q "!main!\%%d"
)
cls
:lengua
echo -------------------------------------------
echo [ 1] NL (v20 or v23)
echo [ 2] DE (v20 or v23)
echo [ 3] AT (v20 or v23)
echo [ 4] BE-Flanders (v20 or v23)
echo [ 5] BE-Wallone (v20 or v23)
echo [ 6] NL (v13)
echo [ 7] DE (v13)
echo [ 8] AT (v13)
echo [ 9] BE-Flanders (v13)
echo [10] BE-Wallone (v13)
echo -------------------------------------------
set "prefix="
set /p "copt=- Choose language: "
echo("!copt!"|C:\Windows\System32\findstr /vrxc:"\"[0-910]\"" >nul &&goto lengua
if "!copt!"=="1" set "prefix=PN"
if "!copt!"=="2" set "prefix=PD"
if "!copt!"=="3" set "prefix=PO"
if "!copt!"=="4" set "prefix=PV"
if "!copt!"=="5" set "prefix=PW"
if "!copt!"=="6" set "prefix=PN"
if "!copt!"=="7" set "prefix=PD"
if "!copt!"=="8" set "prefix=PO"
if "!copt!"=="9" set "prefix=PV"
if "!copt!"=="10" set "prefix=PW"
for /f "tokens=1 delims=" %%e in ('dir /b "!main!\*.txt"') do (
set "txt=%%e"
if /i "!txt:~0,2!"=="pb" set "num3=!num2:~-3!"&set "lang=K"
if /i not "!txt:~0,2!"=="pb" set "num3=!num2:~-2!"&set "lang=S"
if /i "!txt:~-5!"=="r.txt" (ren "!main!\%%e" "!prefix!!lang!!JD!!num3!R.txt") else (ren "!main!\%%e" "!prefix!!lang!!JD!!num3!.txt")
set /a "num2+=1"
)
set /a "num+=1"
set "fname=!base!!petsa!_!num:~-3!"
ren "!main!" "!fname!"
for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
echo !fname! %%G !county!>>SummaryReport_!petsa!.csv
)
)
endlocal
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:finout
setlocal enabledelayedexpansion
:process
for /f "tokens=1 delims=" %%a in ('dir /b "PAB*."') do (
set "file=%%a"
if not exist "!file!" md "!file!"
set "dcount=0"
set "rcount=0"
for /f "tokens=1 delims=" %%c in ('dir /b "!file!\*."') do (
for /f "tokens=1 delims=" %%d in ('dir /b "!file!\%%c\*.tif?"') do (
set /a "dcount+=1"
)
for /f "tokens=1 delims=" %%e in ('dir /b "!file!\%%c\*."') do (
for /f "tokens=1 delims=" %%f in ('dir /b "!file!\%%c\%%e\*.tif?"') do (
set /a "rcount+=1"
)
)
)
set /a "tifcount=!dcount! + !rcount!"
set "petsa=!date:~-10!"
set "petsa2=!petsa:/=-!"
set "tstamp=!petsa2:~6,4!-!petsa2:~0,5!T!time:~0,8!
>"!file!_RAP.xml" echo ^<?xml version="1.0" encoding="UTF-8"?^>
>>"!file!_RAP.xml" echo ^<ScanpostBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"^>
>>"!file!_RAP.xml" echo ^<BatchID^>Scanpost_!file!^</BatchID^>
>>"!file!_RAP.xml" echo ^<CreationDate^>!tstamp!^</CreationDate^>
>>"!file!_RAP.xml" echo ^<Customer^>PABO^</Customer^>
>>"!file!_RAP.xml" echo ^<Documentstream^>EZ1103^</Documentstream^>
>>"!file!_RAP.xml" echo ^<Product^>Maatwerk^</Product^>
>>"!file!_RAP.xml" echo ^<Report^>
>>"!file!_RAP.xml" echo ^<NumberOfMailpacksReceived^>!tifcount!^</NumberOfMailpacksReceived^>
>>"!file!_RAP.xml" echo ^<NumberOfMailpacksResendToCustomer^>0^</NumberOfMailpacksResendToCustomer^>
>>"!file!_RAP.xml" echo ^<NumberOfMailpacksRetrievedForCustomer^>0^</NumberOfMailpacksRetrievedForCustomer^>
>>"!file!_RAP.xml" echo ^<NumberOfMailpacksDestroyed^>0^</NumberOfMailpacksDestroyed^>
>>"!file!_RAP.xml" echo ^<NumberOfDocumentsReceived^>!tifcount!^</NumberOfDocumentsReceived^>
>>"!file!_RAP.xml" echo ^<NumberOfDocumentsLeft^>0^</NumberOfDocumentsLeft^>
>>"!file!_RAP.xml" echo ^</Report^>
>>"!file!_RAP.xml" echo ^</ScanpostBatch^>
>>"!file!_TRIG.xml" echo ^<?xml version="1.0" encoding="UTF-8"?^>
>>"!file!_TRIG.xml" echo ^<ScanpostBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"^>
>>"!file!_TRIG.xml" echo ^<BatchID^>Scanpost_!file!^</BatchID^>
>>"!file!_TRIG.xml" echo ^<CreationDate^>!tstamp!^</CreationDate^>
>>"!file!_TRIG.xml" echo ^<Customer^>PABO^</Customer^>
>>"!file!_TRIG.xml" echo ^<Documentstream^>EZ1103^</Documentstream^>
>>"!file!_TRIG.xml" echo ^<Product^>Maatwerk^</Product^>
>>"!file!_TRIG.xml" echo ^<Batch^>
>>"!file!_TRIG.xml" echo ^<ScanBatchFileName^>!file!.zip^</ScanBatchFileName^>
>>"!file!_TRIG.xml" echo ^<NumberOfDocumentsDelivered^>!dcount!^</NumberOfDocumentsDelivered^>
>>"!file!_TRIG.xml" echo ^<NumberOfDocumentsUnDelivered^>!rcount!^</NumberOfDocumentsUnDelivered^>
>>"!file!_TRIG.xml" echo ^<NumberOfPagesDelivered^>!tifcount!^</NumberOfPagesDelivered^>
>>"!file!_TRIG.xml" echo ^<NumberOfImagesDelivered^>!tifcount!^</NumberOfImagesDelivered^>
>>"!file!_TRIG.xml" echo ^<NumberOfDocumentsLeft^>0^</NumberOfDocumentsLeft^>
>>"!file!_TRIG.xml" echo ^</Batch^>
>>"!file!_TRIG.xml" echo ^</ScanpostBatch^>
echo Zipping files, please wait...
cd !file!
c:\7zip\7z a "!file!".zip "*"
cd..
if not exist "FOR RELEASE" md "FOR RELEASE"
move "!file!\*.zip" "FOR RELEASE"
move "!file!*.xml" "FOR RELEASE"
rd /s /q "!file!"
)
endlocal
cls
echo.
echo Done zipping and creating xml...
echo.
:oro
set /p "othero=-Process another files? [Y/N]: "
echo("%othero%"|C:\Windows\System32\findstr /vrxc:"\"[ny]\"" >nul &&goto oro
if /i "%othero%"=="y" set /a "num+=1"&goto menu
if /i "%othero%"=="n" exit /b
Sorry if it's not professionally written, I'm not pro on this, still learning, but if you can improve it, thanks in advance. And also, if you notice in my code, I'm calling the dos commands in full path, it's because I've encountered weird error: 'dos command' is not recognized as an internal or external command, operable program or batch file.
Here my input files: http://www.mediafire.com/?nwsg240s0xtb6pc
Zip program: http://www.mediafire.com/?i695tgx9vlso3t9
my folder structure: D:\TEST\current date here eg.11-19-2011
Thanks in advance.