Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #155 Delete file

Delete from filesystem the file having path filepath.

#include <unistd.h>
int main(void)
{
	if (unlink(filepath) == -1)
		err(1, "unlink");
	return 0;
}
using System.IO;
File.Delete(filepath);
import std.file;
try
    remove(filepath);
catch (FileException fe)
    writeln(fe.msg);
  open (10,file=filepath,status="old", iostat=ierr)
  if (ierr == 0) close (10,status="delete")
import "os"
err := os.Remove(filepath)
const fs = require('fs');
try {
  fs.unlinkSync(_filepath);
} catch (err) {
  console.error(err);
}
import java.io.File;
new File(filepath).delete();
unlink($filepath);
SysUtils
begin
  if DeleteFile(filepath) then
    writeln(filepath,' succesfully deleted.')
  else
    writeln('Error deleting ',filepath);
end.
unlink $filepath;
import pathlib
path = pathlib.Path(_filepath)
path.unlink()
File.delete(filepath)
use std::fs;
fs::remove_file(filepath);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms