[mapserver-users] temporary files deletion

Dave Vieglais vieglais at ukans.edu
Tue May 15 11:43:25 EDT 2001


We use a simple script that is called from a page that is hit fairly often
by web users.  The IIS script scans a specified directory and deletes any
files older than so many minutes using the functionality provided by the
FileSystemObject.  Sort of a user rather timer driven event source.  If
you're worried about calling this function too often (it does use some
resources), set a global variable in your Application object that tracks the
last time the method was called.

Java script source follows.

good luck,
  Dave V.

--- snip ---
/*=======================================================
Delete files from the directory path, with extenstion ext
that are have not been accessed for t0Minutes or are were
created more than t1Minutes ago.
[in]
	t0Minutes: integer = number of minutes since last accessed to delete
	t1Minutes: integer = number of minutes since created to delete
	path: string = path to directory containing files to delete
	sExt: string = extension of files to remove (no "." included)
========================================================*/
function DeleteOldFiles(t0Minutes,t1Minutes,path,sExt)
{
	var ofs = Server.CreateObject("Scripting.FileSystemObject");
	sExt = sExt.toLowerCase();
	try
	{
		var dt = new Date();
		var oFolder = ofs.GetFolder(path);
		var oFile = null;
		var i=0;
		var fc = new Enumerator(oFolder.Files);
		for (; !fc.atEnd(); fc.moveNext())
		{
			oFile = fc.item();
			var afname = oFile.Name.split(".");
			if (afname[afname.length-1].toLowerCase() == sExt)
			{
				var fdt0 = oFile.DateLastAccessed;
				var fdt1 = oFile.DateCreated;
				var d0 = (dt-fdt0)/(1000*60);
				var d1 = (dt-fdt1)/(1000*60);
				if ((d0>t0Minutes) || (d1 > t1Minutes))
				{
					ofs.DeleteFile(oFile.Path);
				}
			}
		}
	}
	catch (e)
	{
	}
}

--- snip ---

>-----Original Message-----
>From: owner-mapserver-users at lists.gis.umn.edu
>[mailto:owner-mapserver-users at lists.gis.umn.edu]On Behalf Of Speh
>Sylvain
>Sent: Tuesday, May 15, 2001 8:56 AM
>To: Assefa Yewondwossen
>Cc: mapserver-users at lists.gis.umn.edu
>Subject: RE: [mapserver-users] temporary files deletion
>
>
>Yes, why not, but, what about mapServer under W95 which is not
>provided with
>a scheduler/chrontable ?
>
>Someone here was trying to use a VB script into an HTML page ( like some
>virus do ), but we could'nt achieve it.
>
>Any Idea ?
>
>-----Message d'origine-----
>De : Assefa Yewondwossen [mailto:assefa at dmsolutions.ca]
>Envoyé : lundi 14 mai 2001 22:01
>À : mapserver
>Objet : Re: [mapserver-users] temporary files deletion
>
>
>Hi There,
>
> For those of you who use windows, there is an executable on our site that
>can be used to delete tmp files created by mapserver.
>
>http://www2.dmsolutions.on.ca/webtools/dl/deltmpfiles.zip
>
>Note : I did some initial testing but I will start testing it on our
>internal server begining today.
>
>Later,
>
>Assefa Yewondwossen wrote:
>
>> Hi,
>>
>>  Does any one has a bat file or an exe file (or other means) that I can
>> use to delete files on windows based on the time of the files. I would
>> like to be able to delete tmp gif files generated by mapserver that are
>> older that x time.
>>
>> Thanks,
>>
>> --
>> ----------------------------------------------------------------
>> Assefa Yewondwossen
>> Software Analyst
>>
>> Email: assefa at dmsolutions.ca
>> http://www.dmsolutions.ca/
>>
>> Phone: (613) 565-5056
>> ----------------------------------------------------------------
>
>--
>----------------------------------------------------------------
>Assefa Yewondwossen
>Software Analyst
>
>Email: assefa at dmsolutions.ca
>http://www.dmsolutions.ca/
>
>Phone: (613) 565-5056
>----------------------------------------------------------------
>




More information about the mapserver-users mailing list