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

Author Topic: I want to delete a file if the creation date is not current.  (Read 3616 times)

0 Members and 1 Guest are viewing this topic.

THamblin

    Topic Starter


    Greenhorn

    I want to delete a file if the creation date is not current.
    « on: September 18, 2008, 10:50:18 AM »
    I have updated the configuration file for my software distribution solution.  I want to delete the existing configuration file if the creation date is older than the newly created configuration file.
     ???
    Thanks,
    Todd

    THamblin

      Topic Starter


      Greenhorn

      Re: I want to delete a file if the creation date is not current.
      « Reply #1 on: September 18, 2008, 11:04:40 AM »
      This is my current solution.  I've tried to adapt some the ideas I found
      in the forum to create a new solution, but no luck so far.

      rem /* ================================ */
      rem /* WSUS registry entry.             */
      rem /* 09/23/08 -tah                    */
      rem /* ================================ */


      DIR C:\NET\sus_client\wsus-*.reg | FIND  "/2008" > nul
      if not errorlevel==1 (goto _WSUS
      ) ELSE (goto _WSUS_No
              )
      )
      GOTO _WSUS_END


      :_WSUS
      ECHO The date on this file does match.
      GOTO _WSUS_END


      :_WSUS_No
      ECHO Doesn't match.
      ATTRIB -R C:\NET\sus_client\wsus-*.reg
      DEL C:\NET\sus_client\wsus-*.reg


      :_WSUS_END


      Thanks,
      Todd

      gpl



        Apprentice
      • Thanked: 27
        Re: I want to delete a file if the creation date is not current.
        « Reply #2 on: September 18, 2008, 11:18:59 AM »
        Im not sure whether you want to keep only the latest configuration, or remove a configuration set if it is superseded.

        If you want to have only the most up to date files, then xcopy will do it for you - taken from the online help
        /D:m-d-y     Copies files changed on or after the specified date.
                     If no date is given, copies only those files whose
                     source time is newer than the destination time.

        Does this help ?
        Graham

        Dias de verano

        • Guest
        Re: I want to delete a file if the creation date is not current.
        « Reply #3 on: September 18, 2008, 11:56:20 AM »
        Code: [Select]
        if not errorlevel==1
        That should be

        Code: [Select]
        if %errorlevel% NEQ 1

        THamblin

          Topic Starter


          Greenhorn

          Re: I want to delete a file if the creation date is not current.
          « Reply #4 on: September 18, 2008, 02:19:39 PM »
          I'm not sure whether you want to keep only the latest configuration, or remove a configuration set if it is superseded.

          If you want to have only the most up to date files, then xcopy will do it for you - taken from the online help
          /D:m-d-y     Copies files changed on or after the specified date.
                       If no date is given, copies only those files whose
                       source time is newer than the destination time.

          Does this help ?
          Graham
          Graham,

          Your suggestion would work perfectly if I was using a batch file to replace the current configuration file.

          My problem is that I have 22 subnets and a different configuration file for each subnet.  A program runs during the login process and determines the 3rd octet of the PC.  Then a configuration file is created on the PC based on the 3rd octet.  The configuration file points the computer to a specific software distribution server.

          My objective is to delete the current configuration file.  That will trigger the application to create a new configuration file.  The new configuration file will have a new creation date.  If the PC has a new configuration file, I don't want to delete it with my login script the next time my user logs into the PC.

          Hopefully you have more.  I want to delete the configuration file if it is older than the date I specify in my batch file.

          Thank you for your response!!!
           :)
          Todd

          THamblin

            Topic Starter


            Greenhorn

            Re: I want to delete a file if the creation date is not current.
            « Reply #5 on: September 19, 2008, 08:28:18 AM »
            Code: [Select]
            if not errorlevel==1
            That should be

            Code: [Select]
            if %errorlevel% NEQ 1

            Días de verano,

            Gracias por su ayuda.

            This is the only way I know to get the date on the file.
            ***
            set todd=(
            DIR C:\NET\sus_client\wsus-*.reg)

            C:\Documents and Settings\THamblin>DIR C:\NET\sus_client\wsus-*.reg
             Volume in drive C has no label.
             Volume Serial Number is 680C-4B0F

             Directory of C:\NET\sus_client

            12/04/2006  10:56 AM             2,010 wsus-cc.reg
                           1 File(s)          2,010 bytes
                           0 Dir(s)  11,905,589,248 bytes free

            C:\Documents and Settings\THamblin>
            ***

            Then I saw this in the forum and thought I could use it if I could set the date of the file as a variable.
            ***
            for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set hope= %%e/%%f/%%g
            ***

            I could get the right line of text with this.
            ***
            DIR C:\NET\sus_client\wsus-*.reg | FIND "/2006"
            ***

            But I have not found a way to pull the date out of that line of text.

            Any ideas you can come up with would be appreciated.


            Thanks,
            Todd

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: I want to delete a file if the creation date is not current.
            « Reply #6 on: September 19, 2008, 12:15:25 PM »
            I'll be the first to admit that this is a mess, but it seems to work. You're only checking for equality, which is a simple string compare. There is no real need to fix up the dates into yyyymmdd format.

            Code: [Select]
            @echo off
            for /f "tokens=2 delims= " %%i in ("%date%") do (
            set dt=%%i
            )

            for /f "skip=5 tokens=1,7 delims=/ " %%i in ('dir /a-d C:\NET\sus_client\wsus-*.reg') do (
            if %dt% NEQ %%i echo del C:\NET\sus_client\%%~nxj 2>nul
            )

            As written, the script will simply list the files to be deleted. When you are satisfied with the result, remove the word echo from the next to last line.

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

            -- Albert Einstein

            Dias de verano

            • Guest
            Re: I want to delete a file if the creation date is not current.
            « Reply #7 on: September 19, 2008, 12:50:27 PM »
            To get the various dates possibly associated with a file you can use dir with the /T switch and one of these letters:

             C  Creation
             A  Last Access
             W  Last Written

            Thus DIR /TC gets creation date / time

            so:

            Code: [Select]
            @echo off
            REM assumes there is only ONE .reg file in the folder
            for /f %%A ('dir /b /TC C:\NET\sus_client\wsus-*.reg') do set Cdatetime=%%~tA
            for /f "tokens=1,2 delims= " %%D in ("%Cdatetime%") do set Cdate=%%D
            echo creation date: %cdate%
            echo today's  date: %date%
            if not "%cdate%"=="%date%" goto nochange

            REM code to run if dates are different

            :nochange


            I am a bit confused because in the first post, I see this

            Quote from: THamblin
            I want to delete the existing configuration file if the creation date is older than the newly created configuration file.

            But now I see the requirement has changed to deleting the existing configuration file if the the creation date is just different from the newly created one.

            THamblin

              Topic Starter


              Greenhorn

              Re: I want to delete a file if the creation date is not current.
              « Reply #8 on: September 25, 2008, 03:40:17 PM »
              Thank you Sidewinder and Días de verano.  Your ideas have helped me to get my solution.  You are both awesome!!!

              Thanks,
              Todd