Cleaning the /tmp directory

Patrick Weber p.weber at UCL.AC.UK
Wed May 25 04:19:11 EDT 2005


Windows does have scheduled tasks which you can use to run any kind of
program, including batch scripts and so on.

Daniel Caldeweyher wrote:
> On Mon, 23 May 2005 09:29:59 -0700, John Kim <jkim at SCIENCES.SDSU.EDU> wrote:
>
>
>>>from : http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?PHPMapScriptRH72
>>>there is :
>>>Setup MapServer IMAGEDIR and cleanup script
>>>...
>>
>>Any tips on how you'd do this in Windows?
>>
>>Thanks,
>>
>>John
>>
>
>
> I am using JavaMapscript with Tomcat and developed the following class to
> do the automated cleaning for me:
>
> to execute you simple write:
>
> new Thread(new Cleaner()).start()
>
> The temp file path and clean interval (in milliseconds; every 12 hours) is
> loaded from my configuration file. Modifying the code to not delete files
> that have been created in the last couple or minutes or so, should be
> fairly easy to implement:
>
> package au.edu.qpsf.ocis;
>
> import java.io.*;
> /**
>  *
>  * @author Daniel Caldeweyher
>  */
> public class Cleaner implements Runnable {
>     private String tempPath;
>     private volatile boolean active;
>
>     public void run() {
>         this.active = true;
>         while(active) {
>             OpenCIS ocis = OpenCIS.getInstance();
>             tempPath = ocis.getConfigParameter("imagepath");
>             long waitInterval = Long.parseLong(ocis.getConfigParameter
> ("cleanup-interval"));
>
>             File tempDir = new File(tempPath);
>             if(tempDir.exists() && tempDir.isDirectory() && tempDir.canWrite
> ()) {
>                 System.out.println("Start cleanup: " +
> tempDir.getAbsolutePath());
>                 File[] files = tempDir.listFiles();
>                 int numFilesDeleted = 0;
>                 for(File f : files) {
>                     if(f.canWrite()) {
>                         f.delete();
>                         numFilesDeleted++;
>                     }
>                 }
>                 System.out.println("Deleted " + numFilesDeleted + " temp
> files, could not delete " + (files.length - numFilesDeleted) + " files.");
>             }
>
>             try { Thread.sleep(waitInterval);
>             } catch (InterruptedException ie) { active = false; }
>         }
>
>     }
>
>     public void stopCleaner() {
>         active = false;
>     }
>
>     public String getTempPath() {
>         return tempPath;
>     }
>
>     public void setTempPath(String tempPath) {
>         this.tempPath = tempPath;
>     }
> }
>
> This solution will work on any operating system, including windows which is
> missing cron jobs.
>
> Daniel

--
________________________________________

   Patrick Weber | p.weber at ucl.ac.uk

   Research Associate

   Centre for Advanced Spatial Analysis
   http://www.casa.ucl.ac.uk/

   University College London
________________________________________



More information about the mapserver-users mailing list