Delete a file

From CodeCodex

Revision as of 16:37, 7 February 2011 by 211.2.129.92 (Talk)

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')