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

Author Topic: Compare file date to system date and copy to archive  (Read 4366 times)

0 Members and 1 Guest are viewing this topic.

bernardgbailey

    Topic Starter


    Newbie

    Compare file date to system date and copy to archive
    « on: March 25, 2009, 03:52:50 PM »
    Hi team,

    I've created a batch file which sets off a series of processes. 
    I want to add a line into the batch file to test if the date of the file is today.  If not then stop processing.

    At the end of the batch, I want to copy specified files to archive.

    How would I go about these two requirements?

    Cheers
    Bernard

    macdad-



      Expert

      Thanked: 40
      Re: Compare file date to system date and copy to archive
      « Reply #1 on: March 26, 2009, 06:21:20 AM »
      How is the file named? like: 03-26-2009.txt
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      Dias de verano

      • Guest
      Re: Compare file date to system date and copy to archive
      « Reply #2 on: March 26, 2009, 07:35:33 AM »
      How is the file named? like: 03-26-2009.txt


      I believe it's a file creation date that he wants to check, not a file name, but of which file it isn't clear.

      Reno



        Hopeful
      • Thanked: 32
        Re: Compare file date to system date and copy to archive
        « Reply #3 on: March 26, 2009, 07:53:40 AM »
        for today date, there is no need to ask for user system date format, check the following and you will understand.

        Code: [Select]
        +C:\>echo %date%
        Thu 03/26/2009

        +C:\>echo %date:~-10%
        03/26/2009

        +C:\>set d=>file.txt & for %a in (file.txt) do @set d=%~ta & echo %~ta & call echo %d:~0,10%
        03/26/2009 08:50 PM
        03/26/2009

        the %~ta in for loop output modified date i believe. so for creation date, using dir command is one of the method.

        Dias de verano

        • Guest
        Re: Compare file date to system date and copy to archive
        « Reply #4 on: March 26, 2009, 08:04:36 AM »
        the %~ta in for loop output modified date i believe. so for creation date, using dir command is one of the method.

        It returns file creation date on my system

        Also, date string will be different in non-US locales.

        Reno



          Hopeful
        • Thanked: 32
          Re: Compare file date to system date and copy to archive
          « Reply #5 on: March 26, 2009, 08:14:42 AM »
          now i set my regional setting to albanian:

          Code: [Select]
          +C:\>echo %date%
          2009-03-26

          +C:\>echo %date:~-10%
          2009-03-26

          +C:\>set d=>file.txt & for %a in (file.txt) do @set d=%~ta & echo %~ta & call echo %d:~0,10%
          2009-03-26 09:08MD
          2009-03-26

          we only need to check for equality of 10char string here. no math involved, and no yy mm dd parsing.
          only works for today date though, except bulgarian.

          Dias de verano

          • Guest
          Re: Compare file date to system date and copy to archive
          « Reply #6 on: March 26, 2009, 08:17:33 AM »
          we only need to check for equality of 10char string here

          You're right.

          macdad-



            Expert

            Thanked: 40
            Re: Compare file date to system date and copy to archive
            « Reply #7 on: March 26, 2009, 11:48:52 AM »
            I believe it's a file creation date that he wants to check, not a file name, but of which file it isn't clear.

            FINFO  ;)
            If you dont know DOS, you dont know Windows...

            Thats why Bill Gates created the Windows NT Family.

            bernardgbailey

              Topic Starter


              Newbie

              Re: Compare file date to system date and copy to archive
              « Reply #8 on: March 29, 2009, 01:44:46 PM »
              >I want to add a line into the batch file to test if the date of the file is today.  If not then stop processing.

              I can see the confusion I've created here.  Sorry about that.  I want to test to see the file creation date for NEWBLUES.dbf is the same as the system date; if it is then continue processing.  If it is not then the NEWBLUES.DBF is from an earlier date and we don't want to process this.   

              Does this make more sense?

              >At the end of the batch, I want to copy specified files to archive.

              I meant here, to copy the files into a compressed file.

              Cheers
              Bernard