Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Previous month problem

Posted on 2013-06-11
7
244 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 53

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 53

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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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 53

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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