| 1. |
Solve : I want to delete a file if the creation date is not current.? |
|
Answer» 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. I'm not sure whether you want to keep only the latest configuration, or remove a configuration set if it is superseded.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!!! ToddQuote from: Dias de verano on September 18, 2008, 11:56:20 AM Code: [Select]if not errorlevel==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, ToddI'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. 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. Thank you Sidewinder and Días de verano. Your ideas have helped me to get my solution. You are both AWESOME!!! Thanks, Todd |
|