Skip to content

fs.rmdir() on file (not directory) has "ENOTDIR" on Linux/macOS vs "ENOENT" on Windows #8797

Closed
@jokeyrhyme

Description

@jokeyrhyme
  • Version: 6.6.0
  • Platform: Darwin fulmen.local 16.1.0 Darwin Kernel Version 16.1.0: Mon Sep 12 19:36:59 PDT 2016; root:xnu-3789.20.43~78/RELEASE_X86_64 x86_64
  • Subsystem: "fs" module

Just noticed an inconsistency between Windows and everything else (why, Windows, why?!) for the fs.rmdir() and fs.rmdirSync() built-in functions.

const fs = require('fs')
const path = require('path')

fs.rmdirSync(__filename)

Assuming you save this to a file and node it, this file deletes itself on Windows instead of throwing an error as on Linux and macOS.

Note that fs.unlink() and fs.unlinkSync() consistently result in Errors if used on a directory's path.

Update: the snippet results in an "ENOENT" error on Windows, instead of an "ENOTDIR" error as on Linux / macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions