I'm almost done, but now stucked in duplicate check.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
renzlo
Posts: 116
Joined: 03 May 2011 19:06

I'm almost done, but now stucked in duplicate check.

#1 Post by renzlo » 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:

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.

OJBakker
Expert
Posts: 90
Joined: 12 Aug 2011 13:57

Re: I'm almost done, but now stucked in duplicate check.

#2 Post by OJBakker » 19 Nov 2011 08:28

A quick glance at your code
Errors for external dos commands are not so weird.

With set "path=D:\TEST\%petsa%" you have blocked access to the previous path including access to %windir%\system32 the location of all external dos commands.

Change this line to
path=%path%;D:\TEST\%petsa%
or at least
path=%windir%\system32;D:\TEST\%petsa%

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#3 Post by renzlo » 19 Nov 2011 08:31

Thanks OJBakker, I'll just change the path to rootpath, I forgot that path is a predefined dos command, is that the right description?

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#4 Post by renzlo » 20 Nov 2011 07:55

anyone?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I'm almost done, but now stucked in duplicate check.

#5 Post by Ed Dyreen » 20 Nov 2011 08:23

'
path is no command, it's a pre-defined variable that is set to the contents of a key in registry when cmd is loaded.
I myself don't work with the path, too much of a hassle, I use absolute paths where possible.
Actually, I don't like path at all, I don't like the fact that the entire path is searched for a file named echo every time I use the echo. command !

Personally I feel that if you are going to use the %path% variable, you should overwrite it like for example:

Code: Select all

set "path=C:\;C:\windows\;c:\windows\temp;%MyScriptPath%;%PathsMyScriptUses%;%eg.%;%f**k y** ATI%"

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#6 Post by renzlo » 20 Nov 2011 10:35

Thanks ed, this is now my current script:

Please see the highlighted part, this is the duplicate check part, I'm wondering why the else command is not triggering, it triggers but it only write one line.

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 "rpath=D:\TEST\input\PABO\%petsa%"
rem set "rpath=\\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%"|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%"|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%"|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"
xcopy /s /y "%rpath%\AT" "AT"
set "county=AT"
goto :eof

:NL
if not exist "NL" md "NL"
xcopy /s /y "%rpath%\NL" "NL"
set "county=NL"
goto :eof

:DE
if not exist "DE" md "DE"
xcopy /s /y "%rpath%\DE" "DE"
set "county=DE"
goto :eof

:BE02
if not exist "BE02" md "BE02"
xcopy /s /y "%rpath%\BE02" "BE02"
set "county=BE-Flanders"
goto :eof

:BE04
if not exist "BE04" md "BE04"
xcopy /s /y "%rpath%\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 ('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!"|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!"
::START DUPLICATE CHECK
for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
set "contents=%%G"
if exist "SummaryReport_!petsa!.csv" (
findstr "!contents!" "SummaryReport_!petsa!.csv">nul || echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
) else (
echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
)
::END DUPLICATE CHECK
)
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%"|findstr /vrxc:"\"[ny]\"" >nul &&goto oro
if /i "%othero%"=="y" set /a "num+=1"&goto menu
if /i "%othero%"=="n" exit /b
Last edited by renzlo on 20 Nov 2011 15:22, edited 2 times in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I'm almost done, but now stucked in duplicate check.

#7 Post by Ed Dyreen » 20 Nov 2011 11:14

'
I'm sorry renzlo, but in my opinion your code is a mess, I am not surprised it doesn't work.

Indention is such a nice thing:

Code: Select all

::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"
::)
This kind of code is scanned more easily by the human eye...

Here's a better technique for writing a lengthy file

Code: Select all

> "!file!_TRIG.xml" type nul
>>"!file!_TRIG.xml" (
   echo.       ^<NumberOfDocumentsLeft^>0^</NumberOfDocumentsLeft^>
   echo.   ^</Batch^>
   echo. ^</ScanpostBatch^>
)

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#8 Post by renzlo » 20 Nov 2011 15:28

I apologize for my code ed, and thanks for the tip. My messy codes work by the way, I just don't get how to trigger a duplicate check based on the summary report created.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: I'm almost done, but now stucked in duplicate check.

#9 Post by alan_b » 20 Nov 2011 16:08

renzlo wrote:Please see the highlighted part, this is the duplicate check part, I'm wondering why the else command is not triggering, it triggers but it only write one line.


What else command.

I can see :-

else (
set /a "num2+=1"
)

and

else (ren "!main!\%%e" "!prefix!!lang!!JD!!num3!.txt")

and

else (
echo !fname! !contents! !county!>>SummaryReport_!petsa!.csv
)

I cannot accept that messy code works if you have not included the capability to TEST the code and debug it.

If I ever have a problem with a conditional, such as ELSE, I do not debug it as part of a 1000 line conglomerate,
instead I test the condition with the minimum of irrelevant code around it

e.g.
This is horrendous

Code: Select all

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"


Before I can understand what "else" is testing.

I have to understand

if /i "!txt:~-5!"=="r.txt"

before I understand

!txt:~-5!

I have to understand

for /f "tokens=1 delims=" %%e in ('dir /b "!main!\*.txt"')
Before I understand
'dir /b "!main!\*.txt"'
I have to understand
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

Simply insert a few DIR and ECHO commands and you may see where your script is deviating from your expectations.

If you want others to help then cut out all irrelevant code and expose the fragment which malfunctions.

Alan

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#10 Post by renzlo » 20 Nov 2011 16:47

thanks alan, here's the code that mafunctioned:

Code: Select all

::START DUPLICATE CHECK
for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
set "contents=%%G"
if exist "SummaryReport_!petsa!.csv" (
findstr "!contents!" "SummaryReport_!petsa!.csv">nul || echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
) else (
echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
)
::END DUPLICATE CHECK

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: I'm almost done, but now stucked in duplicate check.

#11 Post by aGerman » 20 Nov 2011 17:24

Ed Dyreen wrote:Indention is such a nice thing

I absolutely agree.

That snippet in indented style ...

Code: Select all

for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
  set "contents=%%G"
  if exist "SummaryReport_!petsa!.csv" (
    findstr "!contents!" "SummaryReport_!petsa!.csv">nul || echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  ) else (
    echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  )

... shows that the parentheses of your for loop are not closed.

Regards
aGerman

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#12 Post by renzlo » 20 Nov 2011 18:15

Hi aGerman,

Thanks for the reply, I've closed it but it still writes the first line only.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: I'm almost done, but now stucked in duplicate check.

#13 Post by alan_b » 21 Nov 2011 02:41

This is my suggestion for debugging your own code :-

Code: Select all

SET N=1000
ECHO Processing Directory "!fname!\*.*" >>SummaryReport_!petsa!.TXT
for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
  set "contents=%%G"
  SET /A N+=1
  ECHO !N! Processing %%G >> >>SummaryReport_!petsa!.TXT
  ECHO !N! Processing "!contents!" >> >>SummaryReport_!petsa!.TXT
  if exist "SummaryReport_!petsa!.csv" (
    ECHO !N! PRESENT  !fname!   !contents!   !county!>>SummaryReport_!petsa!.TXT
    findstr "!contents!" "SummaryReport_!petsa!.csv">nul || echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  ) else (
    ECHO !N!  ABSENT  !fname!   !contents!   !county!>>SummaryReport_!petsa!.TXT
    echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  )
)


That should give you a TXT file that will show exactly what is in the directory you are processing,
and which decision is taken where.

Incidentally, I suspect there is no reason for the extra complication of !contents! in your code,
I believe the code would work the same if you employ %%G throughout.

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: I'm almost done, but now stucked in duplicate check.

#14 Post by renzlo » 21 Nov 2011 10:55

alan_b wrote:This is my suggestion for debugging your own code :-

Code: Select all

SET N=1000
ECHO Processing Directory "!fname!\*.*" >>SummaryReport_!petsa!.TXT
for /f "tokens=1 delims=" %%G in ('dir /s /b "!fname!\*.*"') do (
  set "contents=%%G"
  SET /A N+=1
  ECHO !N! Processing %%G >> >>SummaryReport_!petsa!.TXT
  ECHO !N! Processing "!contents!" >> >>SummaryReport_!petsa!.TXT
  if exist "SummaryReport_!petsa!.csv" (
    ECHO !N! PRESENT  !fname!   !contents!   !county!>>SummaryReport_!petsa!.TXT
    findstr "!contents!" "SummaryReport_!petsa!.csv">nul || echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  ) else (
    ECHO !N!  ABSENT  !fname!   !contents!   !county!>>SummaryReport_!petsa!.TXT
    echo !fname!   !contents!   !county!>>SummaryReport_!petsa!.csv
  )
)


That should give you a TXT file that will show exactly what is in the directory you are processing,
and which decision is taken where.

Incidentally, I suspect there is no reason for the extra complication of !contents! in your code,
I believe the code would work the same if you employ %%G throughout.



thanks for the tip alan. I'll try it.

Post Reply