Hi,
I found a very useful batch file in http://www.robvanderwoude.com/files/yesterday_nt.txt
and changed It a bit to generate an argument that is used by {dgate.exe} running on {c:\CONQUEST}
You may copy the source from here, and save it in DelOldDCMfiles.bat then run it from task scheduler
Be careful
:: Place days to be preserved, back from today
:: Windows NT 4 or later only
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: No command line arguments required
IF NOT [%1]==[] GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
:: Query the registry for the date format and delimiter
:: Parse today's date depending on registry's local date format settings
IF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=MM%sDate%DD%sDate%YYYY
SET tLocal=%%tMonth%%%sDate%%%tDay%%%sDate%%%tYear%%
SET yLocal=%%yMonth%%%sDate%%%yDay%%%sDate%%%yYear%%
IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=DD%sDate%MM%sDate%YYYY
SET tLocal=%%tDay%%%sDate%%%tMonth%%%sDate%%%tYear%%
SET yLocal=%%yDay%%%sDate%%%yMonth%%%sDate%%%yYear%%
IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET LocalFormat=YYYY%sDate%MM%sDate%DD
SET tLocal=%%tYear%%%sDate%%%tMonth%%%sDate%%%tDay%%
SET yLocal=%%yYear%%%sDate%%%yMonth%%%sDate%%%yDay%%
:: Remove the day of week if applicable
FOR %%A IN (%Year%) DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%) DO SET Day=%%A
:: Today's date in YYYYMMDD format
SET SortDate=%Year%%Month%%Day%
:: Today's date in local format
FOR %%A IN (%Date%) DO SET Today=%%A
IF "%Day:~0,1%"=="0" SET Day=%Day:~1%
IF "%Month:~0,1%"=="0" SET Month=%Month:~1%
:: Calculate yesterday's date
CALL :JDate %Year% %Month% %Day%
FOR /F "tokens=1-3" %%A IN ('ECHO %GDate%') DO (
:: Calculate tomorrow's date
FOR /F "tokens=1-3" %%A IN ('ECHO %GDate%') DO (
:: Add leading zero to tDay, yDay, tMonth and/or yMonth if necessary
IF 1%tDay% LSS 20 SET tDay=0%tDay%
IF 1%yDay% LSS 20 SET yDay=0%yDay%
IF 1%tMonth% LSS 20 SET tMonth=0%tMonth%
IF 1%yMonth% LSS 20 SET yMonth=0%yMonth%
:: Yesterday's and tomorrow's date in YYYYMMDD format
SET SortTom=%tYear%%tMonth%%tDay%
SET SortYest=%yYear%%yMonth%%yDay%
::ECHO Format: YYYYMMDD (%LocalFormat%)
::ECHO.==================================
::CALL ECHO Yesterday: %SortYest% (%yLocal%)
::ECHO Today: %SortDate% (%Today%)
CALL ECHO All dicom files stored since Jan1970 to %SortTom% were deleted from the server
ENDLOCAL&SET Yesterday=%SortYest%&SET Today=%SortDate%&SET Tomorrow=%SortTom%
C:\CONQUEST\DGATE --deletestudies:(20000101-%Tomorrow%)
:: * * * * * * * * Subroutines * * * * * * * *
REG.EXE /? 2>&1 | FIND "REG QUERY" >NUL
FOR /F "tokens=1-3" %%A IN ('REG Query "HKCU\Control Panel\International" ^| FINDSTR /R /C:"[is]Date"') DO (
:: Export registry's date format settings to a temporary file, in case REG.EXE is not available
START /W REGEDIT /E %TEMP%.\_TEMP.REG "HKEY_CURRENT_USER\Control Panel\International"
:: Read the exported data
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I "iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I "sDate"') DO SET sDate=%%B
:: Remove quotes from exported values
:: Convert Julian date back to "normal" Gregorian date
:: Argument : Julian date
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
SET /A Q = 4 * %P% / 146097
SET /A R = %P% - ( 146097 * %Q% +3 ) / 4
SET /A S = 4000 * ( %R% + 1 ) / 1461001
SET /A T = %R% - 1461 * %S% / 4 + 31
SET /A U = 80 * %T% / 2447
SET /A GYear = 100 * ( %Q% - 49 ) + %S% + %V%
SET /A GMonth = %U% + 2 - 12 * %V%
SET /A GDay = %T% - 2447 * %U% / 80
FOR %%A IN (P Q R S T U V) DO SET %%A=
IF 1%GMonth% LSS 20 SET GMonth=0%GMonth%
IF 1%GDay% LSS 20 SET GDay=0%GDay%
SET GDate=%GYear% %GMonth% %GDay%
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
SET /A Month1 = ( %2 - 14 ) / 12
SET /A JDate = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %2 - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %3 - 32075
FOR %%A IN (Month1 Year1) DO SET %%A=
ECHO Yesterday.bat, Version 3.10 for Windows NT
ECHO Display yesterday's, today's and tomorrow's dates in sorted and local format
IF "%OS%"=="Windows_NT" CALL :UpCase %~n0
IF "%OS%"=="Windows_NT" ECHO Usage: %UpCase%
IF NOT "%OS%"=="Windows_NT" ECHO Usage: %0
ECHO Notes: Environment variables Yesterday, Today and Tomorrow are set to the
ECHO sorted date values found.
ECHO Adapted for Windows XP with help from Kailash Chanduka.
ECHO Local date code by Frederic Guigand and Rob van der Woude.
ECHO Julian date math algorithms based on Fliegel-Van Flandern algorithm
ECHO from the Astronomical Almanac, provided by Doctor Fenton on the Math
ECHO Forum (http://mathforum.org/library/drmath/view/51907.html), and
ECHO converted to batch code by Ron Bakowski.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" COLOR 00
Display More
Ludwig