Solved

Previous month problem

Posted on 2013-06-11
7
240 Views
Last Modified: 2013-06-11
Here is the deal, we have a contractor that processes our monthly bills, and they then post .zip files of the PDF copies of the bills. The contractor normally gets the .zip files posted before the end of the month, but on short months, like February they are posted the following month. I have the batches, there are three in total, scheduled in task scheduler, they start running on the 25th (soonest day the .zip files could be posted) to the 5th, (the last day the bills could be posted). I need the posted zipped PDF’s as soon as they are available.

After the PDF’s are unzipped they are placed in a folder with the year (YYYY)under the year is two digit month of the billing period, if they are posted before the last day of the month, the billing period is the current month. Between 1 and 5 the PDF bills go into the previous month. This part is working well.

After the bills are unzipped and place in the correct month, I need to do some error checking (making sure all of the PDF bills have been downloaded, checking the one csv file (the index) to make the correct number of bills have been downloaded and send an email with the results. Doing the email with a fourth bat file with blat.

The problem I am having is on the error checking part of the previous month, in this part of the script the batch is looking for the folder 5; I need it to look for 05, in June.
I am new to writing batch files more than one line, I am a bit embarrassed to post my who script, I am sure there are far more elegant ways to write this, but here it is:

@echo off
CD /D "D:\files\public1\Member Services Shared Forms\PDFBills"
set source=D:\files\public1\Member Services Shared Forms\PDFBills\UnZip
set targetRoot=D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    if not exist "%targetRoot%\%%C\%%A" mkdir "%targetRoot%\%%C\%%A"
    move "%%~fF" "%targetRoot%\%%C\%%A"
  )
)



@echo off
cd /d "D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills"
setlocal
setpath=%path%;"D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
set "mm=%date:~4,2%
set /a monthback=%date:~4,2%-1
if %MonthBack% == 100 set MonthBack=112
set monthback=%monthback:~-2%
set "dd=%date:~7,2%"
set "yyyy=%date:~-4%"
set targetRoot==D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills

if exist "%targetRoot%\%%C\%%A" (

Echo There were a total of > "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
attrib.exe /s ./*.* |find /c /v "" >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Files Downloaded for %yyyy%-%mm%  billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo Of them there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.pdf "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo PDF Bills for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo and there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.csv "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo csv Files for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo In the CSV file, there are >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
FOR /F "usebackq delims=" %a IN (%yyyy%\%mm%\AccountList.csv) DO SET /A count+=1 >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Records >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

) Else (

Echo There were a total of > "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.* "%TEMP%" /L /S /Q /Y /d:%monthback%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Files Downloaded for %yyyy%-%monthback% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo Of them there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.pdf "%TEMP%" /L /S /Q /Y /d:%monthback%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo PDF Bills for %yyyy%-%monthback% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo.>> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo.>> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo and there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.csv "%TEMP%" /L /S /Q /Y /d:%monthback%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo csv Files for %yyyy%-%monthback% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo In the CSV file, there are >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
FOR /F "usebackq delims=" %a IN (%yyyy%\%monthback%\AccountList.csv) DO SET /A count+=1 >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Records >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo.>> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

endlocal
)
0
Comment
Question by:NLITech
  • 4
  • 3
7 Comments
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39238723
If I understand you correctly this should get you on the right track.  The basic idea is once you have the month number in a variable you check if it is less than 10, and if so prepend the leading 0 to the left.  Since you are working inside a FOR loop you will need EnableDelayedExpansion as well.  Hope this helps, let me know if you have questions.

@echo off
setlocal EnableDelayedExpansion
cd /d "D:\files\public1\Member Services Shared Forms\PDFBills"
set source=D:\files\public1\Member Services Shared Forms\PDFBills\UnZip
set targetRoot=D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    set MM=%%A
    if !MM! LSS 10 set MM=0!MM!
    if not exist "%targetRoot%\%%C\!MM!" mkdir "%targetRoot%\%%C\!MM!"
    move "%%~fF" "%targetRoot%\%%C\!MM!"
  )
)

Open in new window

~bp
0
 

Author Comment

by:NLITech
ID: 39238867
Bp,
Thank you for tring to help, but I just may be beyond help.
Is this how it should look now?

@echo off
CD /D "D:\files\public1\Member Services Shared Forms\PDFBills"
set source=D:\files\public1\Member Services Shared Forms\PDFBills\UnZip
set targetRoot=D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    if not exist "%targetRoot%\%%C\%%A" mkdir "%targetRoot%\%%C\%%A"
    move "%%~fF" "%targetRoot%\%%C\%%A"
  )
)



@echo off
setlocal EnableDelayedExpansion
cd /d "D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills"
set source=D:\files\public1\Member Services Shared Forms\PDFBills\UnZip
set targetRoot==D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills
set "yyyy=%date:~-4%"
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    set MM=%%A
    if !MM! LSS 10 set MM=0!MM!
    if not exist "%targetRoot%\%%C\!MM!" mkdir "%targetRoot%\%%C\!MM!"
    move "%%~fF" "%targetRoot%\%%C\!MM!"
  )
)
Echo There were a total of > "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
attrib.exe /s ./*.* |find /c /v "" >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Files Downloaded for %yyyy%-%mm%  billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo Of them there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.pdf "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo PDF Bills for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo and there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.csv "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo csv Files for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo In the CSV file, there are >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
FOR /F "usebackq delims=" %a IN (%yyyy%\%mm%\AccountList.csv) DO SET /A count+=1 >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Records >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 39238880
I'm a little confused on what you are showing there.  It looks like there are TWO batch files, not one?  Which one is it that needs to be changed?

~bp
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:NLITech
ID: 39238906
@echo off
setlocal EnableDelayedExpansion
cd /d "D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills"
set source=D:\files\public1\Member Services Shared Forms\PDFBills\UnZip
set targetRoot==D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills
set "yyyy=%date:~-4%"
for %%F in ("%source%\*") do (
  for /f "tokens=1,2,3 delims=/ " %%A in ("%%~tF") do (
    set MM=%%A
    if !MM! LSS 10 set MM=0!MM!
    if not exist "%targetRoot%\%%C\!MM!" mkdir "%targetRoot%\%%C\!MM!"
    move "%%~fF" "%targetRoot%\%%C\!MM!"
  )
)

if exist "%targetRoot%\%%C\%%A" (

Echo There were a total of > "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
attrib.exe /s ./*.* |find /c /v "" >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Files Downloaded for %yyyy%-%mm%  billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo Of them there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.pdf "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo PDF Bills for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo. >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"

Echo and there were >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
xcopy *.csv "%TEMP%" /L /S /Q /Y /d:%mm%-%dd%-%yyyy%  >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo csv Files for %yyyy%-%mm% billing period >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo In the CSV file, there are >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
FOR /F "usebackq delims=" %a IN (%yyyy%\%mm%\AccountList.csv) DO SET /A count+=1 >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
Echo Records >> "D:\files\public1\Member Services Shared Forms\PDFBills\logs\BillCount.txt"
0
 

Author Comment

by:NLITech
ID: 39239342
This is working for both %mm% and %monthback%, so I believe I have it.
@echo off
setlocal EnableDelayedExpansion
cd /d "D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills"
set "mm=%date:~4,2%
set /a monthback=%date:~4,2%-1
if !monthback! LSS 10 set monthback=0%monthback%
set "dd=%date:~7,2%"
set "yyyy=%date:~-4%"
set targetRoot==D:\files\public1\Member Services Shared Forms\PDFBills\MonthlyPDFBills

Thank you BP!
0
 

Author Closing Comment

by:NLITech
ID: 39239344
Thank you!
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 39239593
Sorry was away for a bit, but glad you got to a good place.

~bp
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now