fse-cli icon indicating copy to clipboard operation
fse-cli copied to clipboard

Move files from nested folder to parent

Open mslourens opened this issue 4 years ago • 1 comments

🧩 Feature request

Description

I need to move files from /dist/src to /dist. This is currently not possible with this command: fse move /dist/src /dist, because it will warn that 'dest' already exists. If I try to do it with fse move --all /dist/src /dist nothing happens.

Describe the solution you'd like

If I don't specify the option --overwrite it should move the files in dist/src to /dist like the Unix mv command does.

Describe alternatives you've considered

writing my own custom script using the native fs module

mslourens avatar Jul 28 '21 08:07 mslourens

@mslourens it's the expected behavior coming from node-fs-extra itself, see node-fs-extra - doc - move:

Moves a file or directory, even across devices.

src <String>
dest <String> Note: When src is a file, dest must be a file and when src is a directory, dest must be a directory.
options <Object>
    overwrite <boolean>: overwrite existing file or directory, default is false.
callback <Function>
    err <Error>

So no implicit selection such as wildcard "*" or none dir/file name meaning 'all'.

I don't intend to change it on @atao60/fse-cli side. But it's not the end of the story!

  • it's always possible to ask it to node-fs-extra itself
  • your user case unearthed an issue

Without option '--overwrite':


mkdir -pv level1/level2/level3
# mkdir: created directory 'level1'
# mkdir: created directory 'level1/level2'
# mkdir: created directory 'level1/level2/level3'

touch level1/level2/level3/test{1,2,3}.txt

ls -al level1/level2/level3
# total 8
# drwxrwsr-x 2 pierre developers 4096 Jul 28 11:34 .
# drwxrwsr-x 3 pierre developers 4096 Jul 28 11:34 ..
# -rw-rw-r-- 1 pierre developers    0 Jul 28 11:34 test1.txt
# -rw-rw-r-- 1 pierre developers    0 Jul 28 11:34 test2.txt
# -rw-rw-r-- 1 pierre developers    0 Jul 28 11:34 test3.txt


npx -q @atao60/fse-cli move level1/level2/level3 level1/level2
# Moving file or directory... from 'level1/level2/level3' to 'level1/level2'.
# ERROR thrown while moving file or directory:   dest already exists.

ls -al level1/leve2/level3
# ls: cannot access 'level1/leve2/level3': No such file or directory

Oops! The src dir is deleted even though not moved.

With option '--overwrite', it's even worse: both src & dest dirs are deleted...

Some digging is needed here to figure out if it's a fse-cli issue or a fs-extra one.

atao60 avatar Jul 28 '21 09:07 atao60