Logo

Programming-Idioms

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

Idiom #155 Delete file

Delete from filesystem the file having path filepath.

const fs = require('fs');
try {
  fs.unlinkSync(filepath);
} catch (err) {
  console.error(err);
}
Deno.remove(filepath, { recursive: true }).catch((err) => console.error(err));
import {unlink} from 'fs/promises'
await unlink(filepath)
with Ada.Directories;
Ada.Directories.Delete_File (filepath);
#include <unistd.h>
int main(void)
{
	if (unlink(filepath) == -1)
		err(1, "unlink");
	return 0;
}
#include <filesystem>
auto r = std::filesystem::remove(filepath);
using System.IO;
File.Delete(filepath);
import std.file;
try
    remove(filepath);
catch (FileException fe)
    writeln(fe.msg);
import 'dart:io';
File(filepath).deleteSync();
File.rm(filepath)
open (10,file=filepath,status="old", iostat=ierr)
if (ierr == 0) close (10,status="delete")
import "os"
err := os.Remove(filepath)
import System.Directory (removeFile)
removeFile filePath
import java.io.File;
new File(filepath).delete();
import static java.nio.file.Files.deleteIfExists;
import static java.nio.file.Path.of;
deleteIfExists(of(filepath));
os.remove(filepath)
unlink($filepath);
uses 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()
import os
os.remove(filepath)
File.delete(filepath)
use std::fs;
let r = fs::remove_file(filepath);

New implementation...
< >
programming-idioms.org