Page 1 of 1

FINE THE FILE

Posted: 08 Oct 2007 23:16
by raj_repos
Hi
I am looking for a script whic can check one file in the directory
and that particular file need to compare with current time and
if it's 20 mimutes less than current time the this script need to send an email

for example
current time in windows -- 12:30

in my c:\ dir i have the following files

test1.txt 12:00
sap.txt 12:10
reco.txt 12:30


this script need to chek for sap.txt file this file is less than 20mins to the current time
then this script need to send email

rds

Posted: 10 Oct 2007 20:23
by raj_repos
ANY UPDATE PLS

Posted: 11 Oct 2007 14:39
by jeb
Hi raj_repos,

take a look at the function library
special
:CmpFTime -- compares the time of two files, succeeds if condition is met, fails otherwise

you have to change the compare mechanism a bit, but then you can test if a file is newer than 20minutes.

How to send is another problem, i suppose you will need a seperate mail-client like sendmail or something else.

Ciao

jeb

HI

Posted: 17 Oct 2007 21:47
by raj_repos
Hi jeb
Thanks for your reply
I have external mail client , is it is possibe i can have the script
using that function
rds

Posted: 19 Oct 2007 03:08
by jeb
Hi Raj,

try this

@echo off
setlocal

set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
set /a now=%%a*60 + %%b
)

set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
set /a ftime=%%f * 60 + %%g
)

set /a minunte_diff = now-ftime
if %minunte_diff% GTR 20 echo More than 20 minutes

ciao
jeb

Posted: 25 Oct 2007 01:44
by raj_repos
oK thanks i try this
where i need to put the file name
rds

Posted: 25 Oct 2007 01:53
by raj_repos
when i run i get this error between the code


C:\>@echo off
setlocal
set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
%%a was unexpected at this time.
set /a now=%%a*60 + %%b
Missing operand.
)
set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
%%f was unexpected at this time.
set /a ftime=%%f * 60 + %%g
Missing operand.
)
set /a minunte_diff = now-ftime
0if %minunte_diff% GTR 20 echo More than 20 minutes

Posted: 25 Oct 2007 06:05
by jeb
Hi,

start your batch like
test.bat sap.txt

on my system (WinXP) it works.

Your errors can occour when the time (hours or minutes) are 08 or 09.
Then the parser try to use these numbers as octal(the "0" prefix),
but 08 and 09 aren't octal numbers, therefore it does not work every time.

ok we need some corrections (DosItHelp: Your library needs also corrections at the date/time functions).
I simply prefix a "1" then i got for the time "08:09" the line
set /a now=1%%a*60 + 1%%b - 700
set /a now=108*60 + 109 - 700

700 is 100*60+100, so i got the correct minute value



@echo off
setlocal enableextensions

set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
set /a now=1%%a*60 + 1%%b - 700
)

set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
set /a ftime=1%%f * 60 + 1%%g - 700
)

set /a minunte_diff = now-ftime
if %minunte_diff% GTR 20 (
echo More than 20 minutes, exactly %minunte_diff% minutes
) ELSE (
echo only %minunte_diff% minutes diff
)

CHECK THE FILE

Posted: 04 Nov 2007 21:47
by raj_repos
Hi Jeb

it works , but i put the file name which is not exists also it gives result as follows

C:\>test.bat ak4.txt
More than 20 minutes, exactly 6109 minutes

actually there is no such file (ak4.txt) in this folder

then i put one file called ak.txt and run this batch file the result is

C:\>test.bat ak.txt
only 19 minutes diff

this is correct

why it give the result for the file which is not exists

any place i need to change to look for particular file

rds

Posted: 05 Nov 2007 15:53
by jeb
Hi raj_repos,

why it give the result for the file which is not exists

Code: Select all

set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
  set /a ftime=1%%f * 60 + 1%%g - 700
)

Will result for a non existing file in ftime=0, because the for will do nothing.

you can add

Code: Select all

if not exist "%~1" (
  echo No file - no time - good bye
  goto :eof
)


Good look

jeb

Posted: 09 Nov 2007 03:24
by raj_repos
Hi jeb
sorry for disturbing again
the scripts ia not working at all
if i type without any file name also it gives the results as follows
if i put any new file also same results
pls help

C:\>test.bat
More than 20 minutes, exactly 582 minutes

C:\>test.bat
More than 20 minutes, exactly 6445 minutes

C:\>test.bat
More than 20 minutes, exactly 6446 minutes

C:\>test.bat file1.txt
More than 20 minutes, exactly 721 minutes


the code
------------------------------

@echo off
setlocal enableextensions

set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
set /a now=1%%a*60 + 1%%b - 700
)

set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
set /a ftime=1%%f * 60 + 1%%g - 700
)

set /a minunte_diff = now-ftime
if %minunte_diff% GTR 20 (
echo More than 20 minutes, exactly %minunte_diff% minutes
) ELSE (
echo only %minunte_diff% minutes diff
)

-------------------
rds

Posted: 09 Nov 2007 03:27
by raj_repos
after i added the new code for checkong if the file is not exists
that particular this is working but not for file exists

==============
@echo off
setlocal enableextensions

set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
set /a now=1%%a*60 + 1%%b - 700
)

if not exist "%~1" (
echo No file - no time - good bye
goto :eof
)

set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
set /a ftime=1%%f * 60 + 1%%g - 700
)

set /a minunte_diff = now-ftime
if %minunte_diff% GTR 20 (
echo More than 20 minutes, exactly %minunte_diff% minutes
) ELSE (
echo only %minunte_diff% minutes diff
)
===================================

This is working for if the file is not exists

C:\>testak.bat file111.txt
No file - no time - good bye

--

C:\>testak.bat file1.txt
More than 20 minutes, exactly 727 minutes

actually the file was created only one minutes before

Posted: 09 Nov 2007 05:23
by jeb
Hi raj_repos,
C:\>testak.bat file1.txt
More than 20 minutes, exactly 727 minutes

actually the file was created only one minutes before
interessting ...

On my system it works, so I suppose it could be a problem with different time-formats or so.
Simply add some debugcode, like this

Code: Select all

@echo off
setlocal enableextensions

    echo ------- Now: %time%

set now=0
for /F "tokens=1,2 delims=: " %%a IN ("%time%") DO (
set /a now=1%%a*60 + 1%%b - 700
)

if not exist "%~1" (
echo No file - no time - good bye
goto :eof
)

    for /F %%f IN ("%~t1") DO echo ------- Filetime: %%f
set ftime=0
for /F "tokens=2,3 delims=: " %%f IN ("%~t1") DO (
    echo ------- found: %%f:%%g
set /a ftime=1%%f * 60 + 1%%g - 700
)

set /a minunte_diff = now-ftime
if %minunte_diff% GTR 20 (
echo More than 20 minutes, exactly %minunte_diff% minutes
) ELSE (
echo only %minunte_diff% minutes diff
)


if you can't see the problem, post the results and perhaps I can find a solution.

jeb