Difference between revisions of "Delete a file"

From CodeCodex

(Erlang)
Line 6: Line 6:
 
  #include <stdio.h>
 
  #include <stdio.h>
 
  remove("filename");
 
  remove("filename");
 +
</pre>
 +
 +
===Erlang===
 +
<pre>
 +
file:delete(Filename).
 
</pre>
 
</pre>
  
Line 45: Line 50:
  
 
[[Category:C]]
 
[[Category:C]]
 +
[[Category:Erlang]]
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:Objective Caml]]
 
[[Category:Objective Caml]]

Revision as of 16:37, 7 February 2011

Implementations

C

 #include <stdio.h>
 remove("filename");

Erlang

file:delete(Filename).

Java

    boolean success = (new File("filename")).delete();
    if (!success) {
        // Deletion failed
    }

OCaml

 Sys.remove "filename"

Perl

 unlink "filename";

PHP

  unlink($filename);

Python

import os
try: os.unlink('/path/to/file')
except OSError: pass # Deletion failed...

Ruby

File.delete('/path/to/file')