Saved Bookmarks
| 1. |
Solve : Count files and email ---Batch file? |
|
Answer» Hello All,
C:\test>type Abhi.bat CODE: [Select]@echo off for /f "delims=" %%i in ('cscript //nologo c:\test\evaluate.vbs "date -1"' ) do ( set yesterday=%%i echo yesterday=%yesterday% ) set Today=%DATE:~4,10% echo Today=%Today% dir /OD /A-D | findstr "%yesterday% %Today%" dir /OD /A-D | findstr "%yesterday% %Today%" | find /c /v "" > filecount.txt echo type filecount.txt type filecount.txt rem evaluate.vbs rem Wscript.echo eval(WScript.Arguments(0)) rem Thank Salmon Trout for evaluate.vbs Output: C:\test>Abhi.bat yesterday=5/15/2010 Today=05/16/2010 05/15/2010 03:57 AM 14 trk.txt 05/15/2010 04:43 AM 129 gpl77.bat 05/15/2010 09:56 PM 138 zee4.bat 05/15/2010 09:57 PM 150 tgk.txt 05/16/2010 04:19 AM 361 st0510.bat 05/16/2010 01:20 PM 92 teststr.txt 05/16/2010 09:37 PM 135 yesterday.bat 05/16/2010 10:29 PM 3 filecount.txt 05/16/2010 10:32 PM 466 Abhi.bat type filecount.txt 9 C:\test> Hi marvin, Thanks for the quick reply, question since i am new to writing batch files, where do i give the path to the folder i want a count of, and you have used a .vbs file? Also i do not want a listing of the files, just a count as there could be over 100 files. And how should i go about setting up the email?Quote from: TechAbhi on May 16, 2010, 11:57:45 AM "" Point to filecount.txt, right click and choose send to mail recipient. [recovering disk space - old attachment deleted by admin]Hi Marvin, I will be putting this up on a task scheduler to run every night. How do i set up the email so it sends an email automatically. Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday. [recovering disk space - old attachment deleted by admin]Quote from: TechAbhi on May 17, 2010, 08:36:28 AM Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday.You must create and INSTALL "evaluate.vbs" and in the code show the complete path to evaluate.vbs The batch is run inside the photo folder or show a cd to the photo folder in the code before dir command is run 'cscript //nologo c:\test\evaluate.vbs "date -1"' What did the variable yesterday show at the top of the output? 05/16/2010 ? Do not schedule the batch file until it runs correctly for you. I don't know how to email from batch. Quote from: TechAbhi on May 17, 2010, 08:36:28 AM Did a test run and got a file count of 8, but when i opened the folder saw the file count was much higher for yesterday. It appears the path to the folder on your machine where we need to count new files from yesterday and today is: c:\netpub\ftproot\photos\ Also, the evaluate.vbs does not work on your machine. The batch file will run on a schedule at 2AM ( or so) and we cannot prompt a user for yesterday's date. The batch must run automatically and yesterday's date must be currently assigned to yesterday's variable. All values assigned to ram variables disappear when the batch file is no longer in RAM. I shall modify the original code so we can assign yesterday's date to the RAM variable without using evaluate.vbs or interactive input. I shall post the code today 05/17/2010. Thank you Marvin, appreciate your help.Quote from: TechAbhi on May 17, 2010, 11:07:58 AM Thank you Marvin, appreciate your help. Please try the following code: C:\test>type abhi2.bat Code: [Select]@echo off Rem USE the following code only one time echo 05/16/2010 > yesterday.txt rem erase the above line after 23:50 today set /p yesterday=<yesterday.txt echo yesterday=%yesterday% ) set Today=%DATE% set Today=%DATE:~4,10% echo Today=%Today% cd c:\netpub\ftproot\photos\ rem the above folder is where we count files? dir /OD /A-D | findstr "%yesterday% %Today%" dir /OD /A-D | findstr "%yesterday% %Today%" | find /c /v "" > filecount.txt echo type filecount.txt type filecount.txt echo %Today% > yesterday.txt The following Output is for c:\test\ on my computer C:\test>abhi2.bat yesterday=05/16/2010 Today=05/17/2010 05/16/2010 04:19 AM 361 st0510.bat 05/16/2010 01:20 PM 92 teststr.txt 05/16/2010 09:37 PM 135 yesterday.bat 05/16/2010 10:32 PM 466 Abhi.bat 05/16/2010 10:32 PM 3 filecount.txt 05/17/2010 12:26 PM 483 abhi2.bat 05/17/2010 12:27 PM 14 yesterday.txt type filecount.txt 7 Quote from: TechAbhi on May 16, 2010, 11:57:45 AM How to email from commamd prompt the count. "You can use blat (www.blat.net) to send the email" I have not used www.blat.net Let us know how you send email from the command prompt? |
|