Skip to content

【BUG REPORT】windows copy file to root directory error #36

@maxhub-fe

Description

@maxhub-fe
const cpfile = require('cp-file');
const path = require('path')

const src = path.resolve(__dirname, './index.js');
const dest = "D:\\"
cpfile(src, dest, {
 }).on('progress', (process) => console.log(process)).then(done => console.log({done}))
 .catch(e => console.log(e));

stack:

$ node index.js
{ NestedError: Cannot create directory D:\: EPERM: operation not permitted, mkdir 'D:'
at makeDir.catch.error (d:\code\tset\node_modules\cp-file\fs.js:82:8)
Caused By: Error: EPERM: operation not permitted, mkdir 'D:'
nested:
{ Error: EPERM: operation not permitted, mkdir 'D:' errno: -4048, code: 'EPERM', syscall: 'mkdir', path: 'D:\' },
errno: -4048,
code: 'EPERM',
syscall: 'mkdir',
path: 'D:\',
name: 'CpFileError' }

I found that it was 'make-dir' cause error
mkdir

On Windows, using fs.mkdir() on the root directory even with recursion will result in an error:

fs.mkdir('/', { recursive: true }, (err) => {
  // => [Error: EPERM: operation not permitted, mkdir 'C:\']
});

@sindresorhus help plz !!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions