1.

Solve : In need of a batch file HELP!!!!?

Answer»

Im sorry...totally new to the forum.

What i am in need of is a batch file that looks at the date stamps of a particular file.

We are supposed to get new files from a vendor daily, and I want to use my monitoring program to run the batch file to determine if we have recieved a new file in the last 2 days.

Im totally not a programmer!! HA..

Thanks in advance.

MWelcome to the CH forums.

Quote

We are supposed to get new files from a vendor daily

Will all files be in the same folder?   Will all files have the same extension?   What is your date format?

Please read this.

Quote from: Dusty on June 17, 2009, 03:37:30 PM
Welcome to the CH forums.

Will all files be in the same folder?   Will all files have the same extension?   What is your date format?

Please read this.



Files will ALWAYS be in same folder.... always .txt extension and date format is month/day/year (4 digit year) Windows..

I apologize for not being more thorough.

Thanks.

MThis script is totally untested...  It hopefully will check for a filedate of yesterday and today so that if the date today is the 20th it will check a filedate of 19th and 20th.  If you want to check for 18th 19th and 20th CHANGE the echo otherdate = (Date(^)-1^) command line to echo otherdate = (Date(^)-2^)

Code: [Select]echo off
cls
setlocal

set newfile=%temp%newfile.vbs

(
echo otherdate = (Date(^)-1^)
echo   yy = datePart("yyyy", otherdate^)
echo   mm = datePart("m"   , otherdate^)
echo   dd = datePart("d"   , otherdate^)

echo wscript.echo yy^&" "^&mm^&" "^&dd
)>>%newfile%

FOR /F "tokens=1-3" %%A in ('cscript //nologo %newfile%') do (
        set year=%%A
        set month=%%B
        set day=%%C

)

del %newfile%

        if %month% lss 10 set month=0%month%
        if %day%   lss 10 set day=0%day%

set today=%year%%month%%day%%

for /f "delims=" %%1 in ('dir /b "path\filename.txt"') do (
    set filename=%%1
    set filedate=%%~t1
)


set filedate1=%filedate:~6,4%%filedate:~3,2%%filedate:~0,2%


if %filedate1% geq %today% echo %filename% date/time is %filedate% & exit /b
   echo %filename% date/time %filedate%is not within 2 days of today's date. & exit /b


Good luck.

Edit: changed script in response to Ghostdog74's post below. Quote from: Dusty on June 17, 2009, 05:17:45 PM
If you want to check for 18th 19th and 20th change the set /a command line to set /a today=%today%-2
i am sure you know you can't simply minus a date like this in batch? extra code is needed to check dates for eg if date is 01 Jun and 02 Jun, then 2 days before is 30, 31 may.... Quote from: mattf2171 on June 17, 2009, 03:41:47 PM
Files will ALWAYS be in same folder.... always .txt extension and date format is month/day/year (4 digit year) Windows..

I apologize for not being more thorough.

Thanks.

M
NOTE windows file names cannot have "/".
assuming you can download GNU coreutils  (SEE my sig) you can use GNU date
Code: [Select]echo off
for /f "tokens=*" %%a in ('date_gnu "+%%m/%%d/%%Y" -d yesterday') do ( set yest=%%a)
for /f "tokens=*" %%a in ('date_gnu "+%%m/%%d/%%Y" -d "2 days ago"') do ( set twodaysago=%%a)
echo %yest% %twodaysago%
output
Code: [Select]C:\test>test.bat
06/17/2009 06/16/2009

use the if/else  to compare your dates. Quote from: ghostdog74
i am sure you know you can't simply minus a date like this in batch?

OMG how could I have made such an enormous fup?  Thanks for your timely reminder.  Should have switched on brain when getting out of bed.

D.I am working on modifying the script to suit my situation.

Thanks to all who have responded. Its a great help.

I will post back with results.

M


Discussion

No Comment Found