Logo

Programming-Idioms

  • JS
  • Haskell

Idiom #155 Delete file

Delete from filesystem the file having path filepath.

import System.Directory (removeFile)
removeFile filePath
const fs = require('fs');
try {
  fs.unlinkSync(filepath);
} catch (err) {
  console.error(err);
}

This is synchronous.
Deno.remove(filepath, { recursive: true }).catch((err) => console.error(err));

For Deno runtime. Deno.removeSync is a similar function that is synchronous.
recursive can be set to false, but deleting a non-empty directory will fail.
import {unlink} from 'fs/promises'
await unlink(filepath)

This is asynchronous.
with Ada.Directories;
Ada.Directories.Delete_File (filepath);

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