====== pears.DeleteOldDatabaseLogs ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."DeleteOldDatabaseLogs"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in @DaysToKeep smallint ) returns smallint begin --Deletes all files log files with pattern 000000AA.LOG in current log folder over a given age. Read only flags are ignored. declare @Command char(250); declare @Count smallint; declare @LogFilePathName char(250); declare @LogPath char(250); set @LogFilePathName = "db_property"('LogName'); set @LogPath = "left"(@LogFilePathName,"locate"(@LogFilePathName,'\\',-1)-1); set @Count = 0; for "DeleteLoop" as "DeleteCursor" no scroll cursor for select "file_path" as "DeleteLogFilePathName" from "sp_list_directory"(@LogPath) where "file_type" = 'F' and "upper"("right"("file_path","length"("file_path")-"locate"("file_path",'\\',-1))) regexp '^[[:digit:]]{6}[[:alnum:]]{2}\\.LOG$' and "modified_date_time" < "dateadd"("day",(@DaysToKeep*-1),current date) and "file_path" <> @LogFilePathName for read only do set @Command = "string"('DEL /F "',"DeleteLogFilePathName",'"'); call "xp_cmdshell"(@Command,'no_output)'); set @Count = @Count+1 end for; return @Count end