jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.43k stars 775 forks source link

Error when move child folder to replace parent folder #1003

Closed Zagrios closed 1 year ago

Zagrios commented 1 year ago

I have a folder structure like this : C:\Some\Dir\app\app I want to move C:\Some\Dir\app\app to C:\Some\Dir\app

My code : fs.move(src, dest, {overwrite: true}) Result with error : Error: ENOENT: no such file or directory, rename 'C:\Some\Dir\app\app' -> C:\Some\Dir\app

Without the overwrite : Error: dest already exists. at ....\lib\move\move.js:51:31

I quickly looked at the code of fs-extra, it must come from the fact that you delete the destination folder before so the folder inside no longer exists here : https://github.com/jprichardson/node-fs-extra/blob/cc7b3b22a984de5124131c7897574091c9df00e1/lib/move/move.js#L44

RyanZim commented 1 year ago

The only way to do this is to move the directory to some temporary location, then move it back to the parent path. You can't move a directory into its parent directly.