KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > delete_file


1 /*
2  * delete_file.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: delete_file.java,v 1.5 2004/09/16 18:34:19 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 import java.io.File JavaDoc;
25
26 public final class delete_file extends Primitive1
27 {
28     private delete_file()
29     {
30         super("delete-file", "filespec");
31     }
32
33     // ### delete-file filespec => t
34
public LispObject execute(LispObject arg) throws ConditionThrowable
35     {
36         LispObject truename = Pathname.truename(arg, false);
37         if (arg instanceof Stream)
38             ((Stream)arg)._close();
39         if (truename instanceof Pathname) {
40             // File exists.
41
File JavaDoc file = Utilities.getFile((Pathname)truename);
42             for (int i = 0; i < 5; i++) {
43                 if (file.delete())
44                     return T;
45                 System.gc();
46                 Thread.yield();
47             }
48             StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Unable to delete ");
49             sb.append(file.isDirectory() ? "directory " : "file ");
50             sb.append(truename.writeToString());
51             sb.append('.');
52             return signal(new FileError(sb.toString()));
53         } else {
54             // File does not exist.
55
return T;
56         }
57     }
58
59     private static final Primitive1 DELETE_FILE = new delete_file();
60 }
61
Popular Tags