Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Count files and email ---Batch file  (Read 8893 times)

0 Members and 1 Guest are viewing this topic.

TechAbhi

    Topic Starter


    Greenhorn

    Count files and email ---Batch file
    « on: May 16, 2010, 11:57:45 AM »
    Hello All,

    I would like  to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file
    dir /a "C:xx\" |find /c /v ""

    But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont know how to email the count.
    Please help!

    marvinengland



      Hopeful

      Thanked: 11
      Re: Count files and email ---Batch file
      « Reply #1 on: May 17, 2010, 08:08:13 AM »

      I would like  to count the number of files from a folder and only count the files from yesterday.


      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>
       
       
       
      USA

      TechAbhi

        Topic Starter


        Greenhorn

        Re: Count files and email ---Batch file
        « Reply #2 on: May 17, 2010, 08:20:17 AM »
        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?

        marvinengland



          Hopeful

          Thanked: 11
          Re: Count files and email ---Batch file
          « Reply #3 on: May 17, 2010, 08:25:03 AM »
          ""

          I dont know how to email the count.


          Point to filecount.txt, right click and choose send to mail recipient.

          [recovering disk space - old attachment deleted by admin]
          USA

          TechAbhi

            Topic Starter


            Greenhorn

            Re: Count files and email ---Batch file
            « Reply #4 on: May 17, 2010, 08:28:54 AM »
            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.

            TechAbhi

              Topic Starter


              Greenhorn

              Re: Count files and email ---Batch file
              « Reply #5 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.

              [recovering disk space - old attachment deleted by admin]

              marvinengland



                Hopeful

                Thanked: 11
                Re: Count files and email ---Batch file
                « Reply #6 on: May 17, 2010, 09:06:38 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.
                USA

                marvinengland



                  Hopeful

                  Thanked: 11
                  Re: Count files and email ---Batch file
                  « Reply #7 on: May 17, 2010, 11:05:15 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.

                  « Last Edit: May 17, 2010, 11:39:34 AM by marvinengland »
                  USA

                  TechAbhi

                    Topic Starter


                    Greenhorn

                    Re: Count files and email ---Batch file
                    « Reply #8 on: May 17, 2010, 11:07:58 AM »
                    Thank  you Marvin, appreciate your help.

                    marvinengland



                      Hopeful

                      Thanked: 11
                      Re: Count files and email ---Batch file
                      « Reply #9 on: May 17, 2010, 11:34:36 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
                      « Last Edit: May 17, 2010, 11:58:39 AM by marvinengland »
                      USA

                      marvinengland



                        Hopeful

                        Thanked: 11
                        Re: Count files and email ---Batch file
                        « Reply #10 on: May 17, 2010, 07:26:53 PM »
                        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?
                        USA