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

Author Topic: output files based on two FIND criterias with .bat file.  (Read 8811 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: output files based on two FIND criterias with .bat file.
« Reply #15 on: October 29, 2010, 12:56:06 PM »
So, to summarise ("summarize" in the US) you want to

1. Check the last-written date of c:\temp\script_test.txt (just that file or also c:\temp\test_script.txt?)
2. Establish if the date was today or not.

Is that correct? Please clarify how many file dates you wish to check, and if more than one, what you want the trigger to be? Either? Both?


downat420

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Unknown
    Re: output files based on two FIND criterias with .bat file.
    « Reply #16 on: October 29, 2010, 02:13:18 PM »
    1.  I want to check both files last written date.  In the real project it might 10 file name strings in that FIND statement.
    2.  Then establish if the date was today or not.

    Output the file(s) that was not updated today.

    Salmon Trout

    • Guest
    Re: output files based on two FIND criterias with .bat file.
    « Reply #17 on: October 30, 2010, 01:58:05 AM »
    I see you use the Dir command with the /s switch in your original script. Does this imply that the files you are going to be checking are scattered in various folders under a certain named folder? Is c:\temp just a test folder?

    downat420

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: output files based on two FIND criterias with .bat file.
      « Reply #18 on: October 30, 2010, 03:20:56 AM »
      They do not have to be, whatever is easier for you right now.  I can use independent scripts if that is needed.

      Salmon Trout

      • Guest
      Re: output files based on two FIND criterias with .bat file.
      « Reply #19 on: October 30, 2010, 03:38:35 AM »
      What I am getting at is, where are the files going to be that you want to check? Are they always in fixed places so we can hard code the names and paths into the script, or is it a question of looking for them? Also what do you want to happen if the script finds a file that was NOT modified today?



      downat420

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: output files based on two FIND criterias with .bat file.
        « Reply #20 on: October 30, 2010, 05:04:07 AM »
        Always in the same place.

        Salmon Trout

        • Guest
        Re: output files based on two FIND criterias with .bat file.
        « Reply #21 on: October 30, 2010, 05:13:05 AM »
        Also what do you want to happen if the script finds a file that was NOT modified today?

        We're nearly there...


        downat420

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Unknown
          Re: output files based on two FIND criterias with .bat file.
          « Reply #22 on: October 30, 2010, 06:19:59 AM »
          Output list of to a file. 

          Salmon Trout

          • Guest
          Re: output files based on two FIND criterias with .bat file.
          « Reply #23 on: October 30, 2010, 06:41:58 AM »
          Code: [Select]
          @echo off
          setlocal enabledelayedexpansion

          REM ListItem C:\temp\TestFile001.txt
          REM ListItem C:\temp\TestFile002.txt
          REM ListItem C:\temp\TestFile003.txt
          REM ListItem C:\temp\TestFile004.txt
          REM ListItem C:\temp\TestFile005.txt
          REM ListItem C:\temp\TestFile006.txt
          REM ListItem C:\temp\File Name With Spaces 1.txt
          REM ListItem C:\temp\TestFile008.txt
          REM ListItem C:\temp\TestFile009.txt
          REM ListItem C:\temp\TestFile010.txt
          REM ListItem C:\temp\TestFile011.txt
          REM ListItem C:\temp\TestFile012.txt
          REM ListItem C:\temp\TestFile013.txt
          REM ListItem C:\temp\File Name With Spaces 2.txt

          set reportfile=C:\Temp\Report.txt
          if exist "%reportfile%" del "%reportfile%"
          set TodayDate=%date%

          for /f "tokens=1,2* delims= " %%A in ('type "%0" ^| find "REM ListItem" ^| find /v "for /f"') do (
                  set FileName=%%~dpnxC
                  if exist "!FileName!" (
                  set FileDateTime=%%~tC
                  for /f "tokens=1-2 delims= " %%D in ("!FileDateTime!") do set DatePart=%%D
                  If Not "!DatePart!"=="%TodayDate%" echo !DatePart! !FileName! >> "%reportfile%"
                  )
          )

          Echo Files in list
          echo.
          type "%reportfile%"
          echo.
          pause
          exit

          downat420

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Unknown
            Re: output files based on two FIND criterias with .bat file.
            « Reply #24 on: November 01, 2010, 06:29:25 AM »
            I will take a look at these in a few hours.


            Salmon Trout

            • Guest
            Re: output files based on two FIND criterias with .bat file.
            « Reply #25 on: November 01, 2010, 10:56:10 AM »
            This is your local date format
            Thu 10/28/2010

            But your file date data as provided by this script

            Code: [Select]
            @echo off
            for /f "delims=" %%A in ('dir /s /b /tw c:\temp') do (
            echo %%~tA %%~dpnxA
            )

            looks like this

            10/28/2010 10:20 PM c:\temp\test_1.txt

            Is this right?

            If so I need to alter the way the date string is obtained from %date%



            Salmon Trout

            • Guest
            Re: output files based on two FIND criterias with .bat file.
            « Reply #26 on: November 01, 2010, 12:30:17 PM »
            If so I need to alter the way the date string is obtained from %date%

            Code: [Select]
            @echo off
            setlocal enabledelayedexpansion

            REM ListItem C:\temp\TestFile001.txt
            REM ListItem C:\temp\TestFile002.txt
            REM ListItem C:\temp\TestFile003.txt
            REM ListItem C:\temp\TestFile004.txt
            REM ListItem C:\temp\TestFile005.txt
            REM ListItem C:\temp\TestFile006.txt
            REM ListItem C:\temp\File Name With Spaces 2.txt
            REM ListItem C:\temp\TestFile008.txt
            REM ListItem C:\temp\TestFile009.txt
            REM ListItem C:\temp\TestFile010.txt
            REM ListItem C:\temp\TestFile011.txt
            REM ListItem C:\temp\TestFile012.txt
            REM ListItem C:\temp\TestFile013.txt
            REM ListItem C:\temp\File Name With Spaces 1.txt

            set reportfile=C:\Temp\Report.txt
            if exist "%reportfile%" del "%reportfile%"

            REM here assumes format is like  Mon 11/1/2010
            for /f "tokens=1-3 delims= " %%X in ("%date%") do set TodayDate=%%Y

            for /f "tokens=1,2* delims= " %%A in ('type "%0" ^| find "REM ListItem" ^| find /v "for /f"') do (
                    set FileName=%%~dpnxC
                    if exist "!FileName!" (
                    set FileDateTime=%%~tC
                    for /f "tokens=1-2 delims= " %%D in ("!FileDateTime!") do set DatePart=%%D
                    If Not "!DatePart!"=="%TodayDate%" echo !DatePart! !FileName! >> "%reportfile%"
                          )
            )

            Echo Files in List
            echo.
            type "%reportfile%"
            echo.
            pause
            exit