question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

move() not work when dest name not provided

See original GitHub issue

As I’ve been working on moveSync function, I noticed something about how the move function does its job. I’d like this to be clarified for myself since I want the moveSync to be consistent with move.

When you do something like,

const fs = require('fs-extra')
fs.move('./source/somefile.txt', './source/otherDir/somefile.txt', callback)

it works just fine.

But, when you do like,

const fs = require('fs-extra')
fs.move('./source/somefile.txt', './source/otherDir', callback)

nothing happens.

However, if you run the same examples using Linux mv command on a Terminal, the move operation occurs.

Is this an expected behavior from move function?

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
manidloucommented, Jan 1, 2017

That’s right. I tested it just right now. It throws an EEXIST error. Also,

What about these cases (dest exists in all cases):

source is file, dest is file? source is dir, dest is dir? source is dir, dest if file?

I tested for all these cases too and for all them it throws an EEXIST error.

1reaction
jprichardsoncommented, Nov 13, 2016

Is this an expected behavior from move function?

It’s a common misconception that functions in fs-extra should behave like their Unix counterparts. I understand that because the introduction in the README discusses the Unix counterparts. However, I believe that we as programmers should make our intentions explicit as writing code is easy but going back and reading code is hard.

explicit: (GOOD)

fs.move('./source/somefile.txt', './source/otherDir/somefile.txt', callback)

implicit: (NOT GOOD)

fs.move('./source/somefile.txt', './source/otherDir', callback)

This not working is the expected behavior. However, it really shouldn’t silently fail. It should probably throw an EEXIST error.

What are your thoughts @RyanZim?

Read more comments on GitHub >

github_iconTop Results From Across the Web

moving items not working when filenames that have chars [ ]
Just using -literalpath parameter for move-item ls j:\ | foreach { $itemName = $_.Name.Replace('.', ' ') $destination = ls | where { $itemName...
Read more >
move_uploaded_file - Manual - PHP
This function checks to ensure that the file designated by from is a valid upload file (meaning that it was uploaded via PHP's...
Read more >
shutil — High-level file operations — Python 3.11.1 ...
filename is the full path of the archive. extract_dir is the name of the target directory where the archive is unpacked. If not...
Read more >
"Access Denied" or other errors when you access or work with ...
Issue 1: I receive an "Access Denied" error message when I try to access or work with files and folders · Press and...
Read more >
How to Change Nameservers and Point to Another Provider
By following our guide, your domain will work with your new hosting ... However, your domain name stayed with the old hosting company,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found