Logo

Programming-Idioms

# 155 Delete file
Delete from filesystem the file having path filepath.
Implementation
Go

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Go implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
uses SysUtils;
begin
  if DeleteFile(filepath) then
    writeln(filepath,' succesfully deleted.')
  else
    writeln('Error deleting ',filepath);
end.
File.delete(filepath)
use std::fs;
let r = fs::remove_file(filepath);
import std.file;
try
    remove(filepath);
catch (FileException fe)
    writeln(fe.msg);
import pathlib
path = pathlib.Path(_filepath)
path.unlink()
unlink($filepath);
const fs = require('fs');
try {
  fs.unlinkSync(filepath);
} catch (err) {
  console.error(err);
}
#include <unistd.h>
int main(void)
{
	if (unlink(filepath) == -1)
		err(1, "unlink");
	return 0;
}
unlink $filepath;
using System.IO;
File.Delete(filepath);
open (10,file=filepath,status="old", iostat=ierr)
if (ierr == 0) close (10,status="delete")
import java.io.File;
new File(filepath).delete();
os.remove(filepath)
import {unlink} from 'fs/promises'
await unlink(filepath)
import System.Directory (removeFile)
removeFile filePath
File.rm(filepath)
import 'dart:io';
File(filepath).deleteSync();
with Ada.Directories;
Ada.Directories.Delete_File (filepath);
Deno.remove(filepath, { recursive: true }).catch((err) => console.error(err));
#include <filesystem>
auto r = std::filesystem::remove(filepath);
import os
os.remove(filepath)