File manipulation containing dates DOS BATCH (XP)

WIN XP PRO DOS COMMANDS (date in file name)
Local Settings=UK  dd/MM/yyy

There is a given log file named: logmm_dd_yyyy.txt e.g. log01_14_2005.txt
The date of the file will always be yesterdays date. I need to be able to manipulate this file in batch.

Let say the file is located in a direcory called \stats together with other files such as older files and different txt files.

1) I want to copy only yesterday's file to a directory called \devnew2 for further processing (analog.exe log file processor processes and putputs as html).

2) Assuming (1) has been successful, the now html file will the then be converted into a PDF file using the Ghtmldoc.exe command line utility. As I do not know how to call a date based input file for ghtmldox.exe name and how to ask ghtmldoc.exe to name the output to contain yesterdays date, I am inclined to name the file to something generic such as stats.pdf.  

3) Now I need to rename the stats.pdf file again so that it contains yesterday's date with the following convention:  yyyy_mm_dd_stats.pdf

I need answers to (1) and (3).
(2) is optional but would be nice.
The most elegant answer is worth max points.

Thanks!
DTCNTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

holger12345Commented:
What i understand from what you write is, that you really need to get the date from yesterday, right? Because if you have it stored in a variable you can manipulate it like you want to...

Here is a site with lots of batch files to use. Go to
http://www.robvanderwoude.com/ -> BatchFiles -> Examples -> "D"

There is for example a batch called DateTime that stores date in environement variables

regards Holger
holger12345Commented:
On Rob van der Woude's page i found a batch called yesterday!
Review it if it fits your needs - or better review robs homepage
=========================================
YESTERDAY.BAT:
This batch file uses that same code snippet from version 3 of SORTDATE.BAT too, to display both today's and yesterday's date in two formats:
===========start of the batchfile======================
@ECHO OFF
:: Windows NT 4 or later only
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: No command line arguments required
IF NOT [%1]==[] GOTO Syntax

:: Keep variables local
SETLOCAL

:: Export registry's date format settings to a temporary file
START /W REGEDIT /E %TEMP%.\_TEMP.REG "HKEY_CURRENT_USER\Control Panel\International"

:: Read the exported data
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^¦ FIND /I "iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^¦ FIND /I "sDate"') DO SET sDate=%%B
DEL %TEMP%.\_TEMP.REG

:: Remove quotes from exported values
SET iDate=%iDate:"=%
SET sDate=%sDate:"=%

:: Parse today's date depending on registry's date format settings
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
      SET Year=%%C
      SET Month=%%A
      SET Day=%%B
)
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
      SET Year=%%C
      SET Month=%%B
      SET Day=%%A
)
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
      SET Year=%%A
      SET Month=%%B
      SET Day=%%C
)
:: Remove the day of week if applicable
FOR %%A IN (%Year%)  DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%)   DO SET Day=%%A

:: Today's date in YYYYMMDD format
SET SortDate=%Year%%Month%%Day%

:: Strip leading zero from Day
SET DayS=%Day%
IF %Day:~0,1%==0 SET DayS=%Day:~1%

:: Calculate yesterday's date
IF %DayS% EQU 1 (
      SET YesterY=%Year%
      CALL :RollMonth
) ELSE (
      SET /A YesterD=%DayS% - 1
      SET YesterM=%Month%
      SET YesterY=%Year%
)

:: Add leading zero to YesterD if necessary
IF %YesterD% LSS 10 SET YesterD=0%YesterD%

:: Yesterday's date in YYYYMMDD format
SET SortYest=%YesterY%%YesterM%%YesterD%

:: Display the results
ECHO Format:     YYYYMMDD  (DD/MM/YYYY)
ECHO.==================================
ECHO Today:      %SortDate%  (%Day%/%Month%/%Year%)
ECHO Yesterday:  %SortYest%  (%YesterD%/%YesterM%/%YesterY%)

:: Done
ENDLOCAL
GOTO:EOF

:: * * * * * * * *  Subroutines  * * * * * * * *

:: Subroutine to get yesterday's date if today is the first day of the month
:RollMonth
IF %Month%==01 (
      SET YesterD=31
      SET YesterM=12
      SET /A YesterY = %Year% - 1
)
IF %Month%==02 (
      SET YesterD=30
      SET YesterM=01
)
IF %Month%==03 (
      SET YesterD=28
      SET YesterM=02
      CALL :LeapYear
)
IF %Month%==04 (
      SET YesterD=31
      SET YesterM=03
)
IF %Month%==05 (
      SET YesterD=30
      SET YesterM=04
)
IF %Month%==06 (
      SET YesterD=31
      SET YesterM=05
)
IF %Month%==07 (
      SET YesterD=30
      SET YesterM=06
)
IF %Month%==08 (
      SET YesterD=31
      SET YesterM=07
)
IF %Month%==09 (
      SET YesterD=31
      SET YesterM=08
)
IF %Month%==10 (
      SET YesterD=30
      SET YesterM=09
)
IF %Month%==11 (
      SET YesterD=31
      SET YesterM=10
)
IF %Month%==12 (
      SET YesterD=30
      SET YesterM=11
)
GOTO:EOF

:: Subroutine to calculate if this year is a leap year
:: (I am not sure if the century calculations are right)
:LeapYear
:: If the year divisable by 4 then it is a leap year . . .
SET /A LeapYear = %Year% / 4
SET /A LeapYear = %LeapYear% * 4
IF %LeapYear% EQU %Year% SET YesterD=29
:: . . . unless it is also divisible by 100 . . .
SET /A LeapYear = %Year% / 100
SET /A LeapYear = %LeapYear% * 100
IF %LeapYear% EQU %Year% SET YesterD=28
:: . . . but when it is divisible by 400 it is a leap year again (?)
SET /A LeapYear = %Year% / 400
SET /A LeapYear = %LeapYear% * 400
IF %LeapYear% EQU %Year% SET YesterD=29
GOTO:EOF

:Syntax
ECHO.
ECHO Yesterday.bat,  Version 2.01 for Windows NT 4 / 2000 / XP
ECHO Display today's and yesterday's date in two formats
ECHO.
ECHO Usage:  %0
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Adapted for Windows XP with help from Kailash Chanduka
=================================================
oBdACommented:
This script puts together the name for your log file and for your PDF file; I can't claim to have completely understood what you're doing in step (2), but it seems like you can get it to work if you have a proper name for the PDF file. The log file's name will be in %LogFile% at the end of the script, the PDF file's name accordingly in %PDFFile%.
The leap year check in this is rather crude, but I don't expect the script to last for 95 years ...

@echo off
setlocal enabledelayedexpansion
:: *** This script runs only on XP
:: *** Get the current date into the variables dd, mm, yy:
for /f "tokens=1-3 delims=/" %%a in ("%date%") do (
  set dd=%%a
  set mm=%%b
  set yy=%%c
)
:: *** Remove leading zeroes for date calculation:
if %dd:~0,1%==0 set dd=%dd:~1,1%
if %mm:~0,1%==0 set mm=%mm:~1,1%
:: *** Create an array with the months' lengths:
set i=1
for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do (
  set Days[!i!]=%%a
  set /a i+=1
)
:: *** (crude) check for a leap year:
set /a Leap=yy %% 4
if %Leap%==0 set Days[2]=29
:: *** Check if today is the first and, if so, calculate overflow:
if %dd%==1 (
  set /a mm -= 1
  if !mm! LSS 1 (
    set /a yy -= 1
    set mm=12
  )
)
if %dd%==1 (
  set dd=!Days[%mm%]!
) else (
  set /a dd -= 1
)
:: *** Add the leading zeroes again:
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
:: *** Put together the logfile's and, while we're at it, the PDF file's name:
set LogFile=log%mm%_%dd%_%yy%.txt
set PDFFile=%yy%_%mm%_%dd%_stats.pdf

echo Name of the log file: %LogFile%
echo Name of the PDF file: %PDFFile%

copy "\stats\%LogFile%" "\devnew\%LogFile%"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DTCNTAuthor Commented:
Holger, 50 points for participation and effort.

 oBdA:  This is an excellent solutuion.

Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.