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

Author Topic: plz help me with batch file (check whether new file exists)  (Read 3675 times)

0 Members and 1 Guest are viewing this topic.

chinna

    Topic Starter


    Rookie

    plz help me with batch file (check whether new file exists)
    « on: September 05, 2007, 12:02:29 PM »
    Hi,
        I am new to Dos and need some help. I am searching some 15 files every 30 mins from 12.00am to 7.00am in  schedule tasks. first time search is fine..what ever the files exists it will display but next time when i run, it should display only new files names.

    eg: sun dir
            1.txt
             2.txt

    when i run the script ,the o/p should be " found 2 files "

    Now after 1 hr it has 4 file

    1.txt
    2.txt
    3.txt
    4.txt

    when i run the script now, the o/p should be "found 2 files"

    i.e IT SHOULD SEARCH FOR NEW FILES ONLY THOUGH THE OLD FILES EXISTS.

    Plz help me..

    Thanks in advance...

    chinna


    DeltaSlaya



      Apprentice
    • Google
      Re: plz help me with batch file (check whether new file exists)
      « Reply #1 on: September 07, 2007, 05:39:39 PM »
      Perhaps a log file that says the files that were in there last time would be necessary?

      I'll give it a shot.

      Quote
      @echo off

      set indir=INPUT DIRECTORY

      set log=%temp%\filelog.log
      set /a newc=0
      set /a oldc=0
      set /a change=0

      for /f "delims=" %%I in ('dir /b /a:-d "%indir%"') do (
           set /a newc+=1
      )

      if exist "%log%" (
           set /p oldc=<"%log%"
      )

      >"%log%" echo %newc%

      set /a change=%newc%-%oldc%
      echo There are %newc% files, %change% of them being additional since the last check.
      pause >nul
      « Last Edit: September 08, 2007, 04:24:41 PM by DeltaSlaya »
      System specs:
      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
      ASUS Striker Extreme
      XFX 8600GT XXX Edition
      2x 1gB Corsair XMS2 DDR2-800
      Seagate Barracuda 320gB SATA
      Raidmax Ninja 918 (520W ATXV2.0 PSU)
      -

      ghostdog74



        Specialist

        Thanked: 27
        Re: plz help me with batch file (check whether new file exists)
        « Reply #2 on: September 07, 2007, 11:14:34 PM »
        here's a vbscript
        Code: [Select]
        Option Explicit
        Dim myFolderToSearch,myFile,FileName,OutFile
        Dim objFSO,objFolder,objOutFile
        Dim temp
        myFolderToSearch = "c:\temp"
        OutFile = "c:\test1\latest.txt"
        Set objFSO=CreateObject("Scripting.FileSystemObject")

        If Not objFSO.FileExists(OutFile) Then 'If the checking file does not exist, create
        Set objOutFile = objFSO.CreateTextFile(OutFile,true)
        objOutFile.Write "0"
        objOutFile.Close
        temp = 0
        Else
        Set objOutFile = objFSO.OpenTextFile(OutFile,1) 'read the file
        temp = objOutFile.ReadLine 'get value of last date time stamp
        objOutFile.Close
        End If

        For Each myFile In objFSO.GetFolder(myFolderToSearch).Files
        If objFSO.GetExtensionName(myFile) = "txt" Then
        If myFile.DateLastModified > CDate(temp) Then
        temp=myFile.DateLastModified
        FileName=myFile
        WScript.Echo "FileName found: " & myFile & ", Time: " & temp
        End If
        End If
        Next
        Set objOutFile = objFSO.OpenTextFile(OutFile,2) 'write newest
        objOutFile.Write temp
        objOutFile.Close

        DeltaSlaya



          Apprentice
        • Google
          Re: plz help me with batch file (check whether new file exists)
          « Reply #3 on: September 08, 2007, 04:23:56 PM »
          Two options have been supplied, if possible could you tell us if the task has been overcome?
          System specs:
          Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
          ASUS Striker Extreme
          XFX 8600GT XXX Edition
          2x 1gB Corsair XMS2 DDR2-800
          Seagate Barracuda 320gB SATA
          Raidmax Ninja 918 (520W ATXV2.0 PSU)
          -

          chinna

            Topic Starter


            Rookie

            Re: plz help me with batch file (check whether new file exists)
            « Reply #4 on: September 10, 2007, 10:07:36 PM »
            Hi guys,
                         Thank you for your hard work and helping me..  Its working perfect and once again you.

            regards,
            chinna