Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move files from nested folder to parent #17

Open
mslourens opened this issue Jul 28, 2021 · 1 comment
Open

Move files from nested folder to parent #17

mslourens opened this issue Jul 28, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@mslourens
Copy link

馃З 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 mslourens added the enhancement New feature or request label Jul 28, 2021
@atao60
Copy link
Owner

atao60 commented Jul 28, 2021

@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 atao60 added bug Something isn't working and removed enhancement New feature or request labels Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants