|
Answer» 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
rdsfor /f "tokens=1*" %%a in ('time /t') do set a=%%a <<-- current time set b=%a:~0,2%:%a:~3,2% <<-- current time without extra *censored* set /a c=%b%-20 <<-time minus minutes set d="%c:~0,2%:%a:~3,2% PM" <-- set back to normal format dir *.txt /a >>%temp%\2 & CLS <-- searches for .txt files in current directory for /f "tokens=1*" %%a in ('findstr %d% %temp%\2') do echo %%a>>%temp%\3 find files with times 20 minutes ago for /f "tokens=1*" %%a in ('type %temp%\d') do SEND YOUR EMAIL <--- use program or command to send email with email beeing %%a
for /f "tokens=1*" %%a in ('time /t') do set a=%%a set b=%a:~0,2%:%a:~3,2% set /a c=%b%-20 set d="%c:~0,2%:%a:~3,2% PM" dir *.txt /a >>%temp%\2 & CLS for /f "tokens=1*" %%a in ('findstr %d% %temp%\2') do echo %%a>>%temp%\3 for /f "tokens=1*" %%a in ('type %temp%\d') do SEND YOUR EMAIL
comparing time/date is tricky in batch. here's a vbscript
Code: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder("C:\temp") n=Now For Each myFiles In objFolder.Files If objFSO.GetExtensionName(myFiles) = "txt" Then If DateDiff("n",myFiles.DateLastModified,n) <= 20 Then 'less than 20 minnutes WScript.Echo myFiles End If End If Next usaage: Code: [Select]@echo off cscript /nologo myscript.vbs > newfile rem send email blat newfile -to <[emailprotected]> -server <server> ........ Quote from: Diablo416 on October 11, 2007, 02:52:15 PM set /a c=%b%-20 <<-time minus minutes
might fail if file time is say, 11:59am and current time is say, 12:01 ? correct me if i am wrongyea i see what you mean
i dunno if this will WORK
@ECHO OFF :DIM1 for /f "tokens=1*" %a in ('time /t') do set a=%a set b=%a:~0,2%:%a:~3,2% set f1=%b:~0,1% set f2=%b:~1,1% set f3=%b:~3,1% set f4=%b:~4,1% if '%f3%' == '7' set f3=1 if '%f3%' == '8' set f3=2 if '%f3%' == '9' set f3=3 if '%f1%' == '2' set f1=1 if '%f1%' == '3' set f1=1 if '%f1%' == '4' set f1=1 if '%f1%' == '5' set f1=1 if '%f1%' == '6' set f1=1 if '%f1%' == '7' set f1=1 if '%f1%' == '8' set f1=1 if '%f1%' == '9' set f1=1 set /a c=%b%-20 set d="%c:~0,2%:%a:~3,2%" dir *.txt /a >>%temp%\2 & CLS for /f "tokens=1*" %%a in ('findstr %d% %temp%\2') do echo %%a>>%temp%\3 for /f "tokens=1*" %%a in ('type %temp%\d') do SEND YOUR EMAIL :DIM2you would have to use cacl's as a command. CACL"s is a command that lets you view and modify files of your choice. Quote from: dos nerd on October 13, 2007, 11:15:27 PMyou would have to use cacl's as a command. CACL"s is a command that lets you view and modify files of your choice.
dos nerd, COULD you please ONLY post when BOTH these things are true:-
a. You understand the question
b. You know the answer
(You're getting noticed.)
Dear All Thanks for your support I am testing the script , if any problem i let you know tks rds reposDear All I try all the scripts it is not working , i i did not try the vb script due to i dont have vb install in my machine
pls let me know which script i need to try for thisQuote from: raj_repos on October 17, 2007, 09:36:32 PMDear All I try all the scripts it is not working , i i did not try the vb script due to i dont have vb install in my machine
pls let me know which script i need to try for this
which OS you using, vb COMES native with Windows. Unless you are using pure DOSHI I am using windows xp rdsany update pls rds
|