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

Author Topic: COMPARE DATE MODIFIED WITH CURRENT DATE  (Read 31282 times)

0 Members and 1 Guest are viewing this topic.

MISS VIP

    Topic Starter


    Rookie

    COMPARE DATE MODIFIED WITH CURRENT DATE
    « on: July 01, 2008, 02:46:45 AM »
    HI ,  :)

    IM WRITING a batch file this batch file should compare the date modifid of a file with the current date if the current date is less than 15 min of the file date then copy this file to another directory..

    PLEASE HELP and thanks in advanced ...

    blastman



      Hopeful

      Re: COMPARE DATE MODIFIED WITH CURRENT DATE
      « Reply #1 on: July 01, 2008, 02:49:49 AM »
      what have you got so far???

      Blastman, you are the man. Thank You Very Much!!!!!!!!!



      MISS VIP

        Topic Starter


        Rookie

        Re: COMPARE DATE MODIFIED WITH CURRENT DATE
        « Reply #2 on: July 01, 2008, 02:57:36 AM »
        @ECHO OFF
        CLS

        :START
        IF "%1" == "" S:\AISHA\MSG *.TXT  /* SEARCH FOR TEXT FILE ONLY
        GOTO SER_DATE

        SER_DATE
        /* COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN GOTO COPY_FILE */  


        ==THIS PART IS MISSING == 




        GOTO COPY_FILE
        /* COPY FROM S:\MSG.TXT TO C:\IN */

        COPY_FILE
        IF "%1" == "" XCOPY S:\HII\MSG.TXT   
        IF NOT "%1" == "" XCOPY S:\%1       
        ECHO.                             
        C:\IN


        REM Execute the MS-DOS dir command ever 60 MIN.
        dir
        SLEEP 60
        GOTO START

        Dias de verano

        • Guest
        Re: COMPARE DATE MODIFIED WITH CURRENT DATE
        « Reply #3 on: July 01, 2008, 03:28:45 AM »
        /* COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN GOTO COPY_FILE */

        You don't do comments like this. They start with REM.

        MISS VIP

          Topic Starter


          Rookie

          Re: COMPARE DATE MODIFIED WITH CURRENT DATE
          « Reply #4 on: July 01, 2008, 03:42:17 AM »
          THANKS DIAS  :)

          ANY HINT FOR MY MISSING PART ?

          MISS VIP

            Topic Starter


            Rookie

            Re: COMPARE DATE MODIFIED WITH CURRENT DATE
            « Reply #5 on: July 01, 2008, 03:52:52 AM »
            I CORRECT IT :)

            @ECHO OFF
            CLS

            :START
            IF "%1" == "" S:\AISHA\MSG *.TXT  /* SEARCH FOR TEXT FILE ONLY
            GOTO SER_DATE

            SER_DATE
            REM COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN GOTO COPY_FILE
             :'(





            GOTO COPY_FILE
            REM COPY FROM S:\MSG.TXT TO C:\IN

            COPY_FILE
            IF "%1" == "" XCOPY S:\HII\MSG.TXT   
            IF NOT "%1" == "" XCOPY S:\%1       
            ECHO.                             
            C:\IN
            GOTO SLP


            REM Execute the MS-DOS dir command ever 60 MIN.

            SLP
            SLEEP 60
            GOTO START

            MISS VIP

              Topic Starter


              Rookie

              Re: COMPARE DATE MODIFIED WITH CURRENT DATE
              « Reply #6 on: July 01, 2008, 04:33:00 AM »
              I FOUND THIS CODE

              Code: [Select]
              DIR %1 ¦ FIND /I "%1" > ~ISMODIF.TMP
                  ECHO.>> ~ISMODIF.TMP
                  TYPE ~ISMODIF.TMP ¦ TIME ¦ FIND /I "%1" > ~ISMODIF.BAT
                  ECHO SET CHKDATE=%%4> ENTER.BAT
                  CALL ~ISMODIF.BAT
                  DIR ~ISMODIF.BAT ¦ FIND /I "~ISMODIF.BAT" > ~ISMODIF.TMP
                  ECHO.>> ~ISMODIF.TMP
                  TYPE ~ISMODIF.TMP ¦ TIME ¦ FIND /I "~ISMODIF.BAT" > ~ISMODIF.BAT
                  ECHO SET NOWDATE=%%4> ENTER.BAT
                  CALL ~ISMODIF.BAT
                  IF "%NOWDATE%"=="%CHKDATE%" ECHO %1 was created or modified today

              IS THIS CODE WILL MEET MY REQUIRMENT WHICH IS COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN COPY_FILE  TO DIFFERENT DIRECTORY ???

              ghostdog74



                Specialist

                Thanked: 27
                Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                « Reply #7 on: July 01, 2008, 07:22:11 AM »
                there are abundance of tools out there you can use. the unix Find command , which is ported to windows makes this kind of task seem trivial.
                Otherwise, here's a vbscript
                Code: [Select]

                Set objFS = CreateObject("Scripting.FileSystemObject")
                strFolder = "C:\test"
                dstFolder = "c:\destination"
                Set objFolder = objFSO.GetFolder(strFolder)
                For Each strFiles In objFolder.Files
                If DateDiff("n",strFiles.DateLastModified,Now) > 15 Then
                WScript.Echo strFiles.Name
                objFS.MoveFile strFiles.Name, dstFolder & "\" & strFiles.Name
                End If
                Next

                Dias de verano

                • Guest
                Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                « Reply #8 on: July 01, 2008, 09:54:56 AM »
                Miss VIP, is there a Caps Lock key on your keyboard?

                MISS VIP

                  Topic Starter


                  Rookie

                  Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                  « Reply #9 on: July 01, 2008, 10:54:49 PM »
                  Thankx "ghostdog74 "  :) i'll try to test ur code ...

                  Dias de verano : NO THIER IS NO CAPS LOCK  :P hehehehehehe

                  MISS VIP

                    Topic Starter


                    Rookie

                    Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                    « Reply #10 on: July 03, 2008, 04:17:59 AM »
                    ghostdog74 , how can i attch your code and put it in my code ??

                    i could not be able to add what u wrote in my code !!

                    this is my code and in red is what you wrote :

                    Code: [Select]
                    @ECHO OFF
                    CLS

                    :START
                    IF "%1" == "" S:\AISHA\MSG *.TXT  /* SEARCH FOR TEXT FILE ONLY
                    GOTO SER_DATE

                    SER_DATE
                    REM COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN GOTO COPY_FILE



                    [color=red]Set objFS = CreateObject("Scripting.FileSystemObject")
                    strFolder = "C:\test"
                    dstFolder = "c:\destination"
                    Set objFolder = objFSO.GetFolder(strFolder)
                    For Each strFiles In objFolder.Files
                    If DateDiff("n",strFiles.DateLastModified,Now) > 15 Then
                    WScript.Echo strFiles.Name
                    objFS.MoveFile strFiles.Name, dstFolder & "\" & strFiles.Name
                    End If
                    Next[/color]



                    GOTO COPY_FILE
                    REM COPY FROM S:\MSG.TXT TO C:\IN

                    COPY_FILE
                    IF "%1" == "" XCOPY S:\HII\MSG.TXT   
                    IF NOT "%1" == "" XCOPY S:\%1       
                    ECHO.                             
                    C:\IN
                    GOTO SLP


                    REM Execute the MS-DOS dir command ever 60 MIN.

                    SLP
                    SLEEP 60
                    GOTO START




                    thanks in advance ....

                    ghostdog74



                      Specialist

                      Thanked: 27
                      Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                      « Reply #11 on: July 03, 2008, 05:47:12 AM »
                      it is a vbscript.
                      save the code as script.vbs and on command line just type

                      Code: [Select]
                      C:\test> cscript /nologo script.vbs
                      assuming your script is stored in c:\test

                      MISS VIP

                        Topic Starter


                        Rookie

                        Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                        « Reply #12 on: July 06, 2008, 09:48:08 PM »
                        thankx "ghostdog74 " for ur effort --

                        i got some error  :'(


                        my batch file code is like that :

                        Code: [Select]
                        @ECHO OFF
                        CLS

                        :START
                        REM SEARCH FOR TEXT FILE ONLY

                        IF "%1" == "" S:\AISHA\MSG *.TXT   GOTO SER_DATE

                        SER_DATE
                        REM COMPARE DATE MODIFIED WITH CURRENT DATE IF SYS<=15 MIN THEN GOTO COPY_FILE

                        REM it will go to the vbs file

                        C:\IN> cscript /nologo script.vbs



                        REM Execute the MS-DOS dir command ever 60 MIN.

                        SLP
                        SLEEP 60
                        GOTO START

                        and my vbs file is like that :


                        Code: [Select]
                        Set objFS = CreateObject("Scripting.FileSystemObject")
                        strFolder = " S:\AISHA\MSG *.TXT"
                        dstFolder = "C:\IN"
                        Set objFolder = objFSO.GetFolder(strFolder)
                        For Each strFiles In objFolder.Files
                        If DateDiff("n",strFiles.DateLastModified,Now) > 15 Then
                        WScript.Echo strFiles.Name
                        objFS.MoveFile j:\msg.txt, dstFolder & "\" & strFiles.Name
                        End If
                        Next
                        goto copy_file


                        where is the error ???

                        ghostdog74



                          Specialist

                          Thanked: 27
                          Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                          « Reply #13 on: July 07, 2008, 05:36:12 AM »
                          i don't know , you tell me.

                          macdad-



                            Expert

                            Thanked: 40
                            Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                            « Reply #14 on: July 07, 2008, 06:23:21 AM »
                            ok you need to learn how to program in batch code, we're not your servants, we can help u but you have to think on your own.

                            where is the error ???
                            open up VB express and debug it, it will tell you the errors and on wat line they are.

                            and

                            look at the attachment

                            noticed how i used all lower case without caps.

                            [recovering disk space -- attachment deleted by admin]
                            If you dont know DOS, you dont know Windows...

                            Thats why Bill Gates created the Windows NT Family.

                            MISS VIP

                              Topic Starter


                              Rookie

                              Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                              « Reply #15 on: July 13, 2008, 03:48:21 AM »
                              thankx "ghostdog74" i'll fine out the error and i'll tell you

                              Dias de verano

                              • Guest
                              Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                              « Reply #16 on: July 13, 2008, 01:52:43 PM »
                              Code: [Select]
                              IF "%1" == "" S:\AISHA\MSG *.TXT   GOTO SER_DATE
                              This line is nonsense.

                              Also, if SER_DATE is a label, it should start with a colon.

                              Code: [Select]
                              C:\IN> cscript /nologo script.vbs
                              Why is C:\IN> at the beginning? This will not work.

                              Code: [Select]
                              REM Execute the MS-DOS dir command ever 60 MIN.

                              SLP
                              SLEEP 60
                              GOTO START

                              What is SLP? A label? a program? Why is it there?

                              Execute the dir command? Where? How?



                              MISS VIP

                                Topic Starter


                                Rookie

                                Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                                « Reply #17 on: July 13, 2008, 09:47:21 PM »
                                 hi Dias de verano ,

                                the first code

                                 
                                Code: [Select]
                                IF "%1" == "" S:\AISHA\MSG *.TXT   GOTO SER_DATEit will go to aisha file in S drive and search only for text files. then it will go to ser_date command.

                                Code: [Select]
                                C:\IN> cscript /nologo script.vbs
                                C:\IN is the name of the folder where i kept my script.vbs

                                Code: [Select]
                                REM Execute the MS-DOS dir command ever 60 MIN.

                                SLP
                                SLEEP 60
                                GOTO START

                                SLP is the name of the command if the previous code execute perfectly then it will go to SLP to sleep for 60 min then it eill go to start to start again..


                                am i doing somthing wrong ?

                                thankx for ur helps guys..

                                MISS VIP

                                  Topic Starter


                                  Rookie

                                  Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                                  « Reply #18 on: July 20, 2008, 04:16:10 AM »
                                  Code: [Select]
                                  N=Now
                                  Set objFSO = CreateObject("Scripting.FileSystemObject")
                                  strFolder=" S:\out"
                                  strNewDest = "C:\IN"
                                  Set objFolder = objFSO.GetFolder(strFolder)
                                  For Each strFiles In objFolder.Files
                                        If DateDiff("d",N, strFiles.DateLastModified) >1  Then           
                                              'objFSO.MoveFile strFiles , strNewDest & "\" & strFiles.Name
                                                  Wscript.Echo strFiles.Name
                                        End If
                                  Next


                                  i tried this VBS code .. it gave an error in the fifth line and the error is (path not found )?!

                                  the one is calculated as one day how can i convert it to min. ?

                                  thanks in advance

                                  Dias de verano

                                  • Guest
                                  Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                                  « Reply #19 on: July 20, 2008, 04:47:17 AM »
                                  Quote
                                  strFolder=" S:\out"

                                  Try removing the space before the S:\out
                                  « Last Edit: July 20, 2008, 06:47:34 AM by Dias de verano »

                                  Sidewinder



                                    Guru

                                    Thanked: 139
                                  • Experience: Familiar
                                  • OS: Windows 10
                                  Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                                  « Reply #20 on: July 20, 2008, 06:44:12 AM »
                                  Quote
                                  the one is calculated as one day how can i convert it to min. ?

                                  Do the arithmetic in minutes:

                                  Code: [Select]
                                  If DateDiff("n", strFiles.DateLastModified, Now) > 15 Then

                                  I think this was the original code. Something may have gotten lost in the translation.

                                   8)
                                  The true sign of intelligence is not knowledge but imagination.

                                  -- Albert Einstein

                                  ALAN_BR



                                    Hopeful

                                    Thanked: 5
                                    • Computer: Specs
                                    • Experience: Experienced
                                    • OS: Windows 7
                                    Re: COMPARE DATE MODIFIED WITH CURRENT DATE
                                    « Reply #21 on: September 01, 2008, 09:41:08 AM »
                                    There seems to be a fundamental flaw from the very first post.

                                    From the ambitions / intentions expressed in the comments it appears that :-
                                    a) Any recent file that is less than 15 minutes of age is to be archived;
                                    b) The above rule will exclude from archiving any thing created / altered in the next 45 minutes, unless the SLEEP period is reduced from 60 minutes down to 15.

                                    Regards
                                    Alan