Support for `dest` being a directory when using `copy*()`?
See original GitHub issueWhen using copySync()
(and, I assume, copy()
too): if src
is a file path and dest
is a directory path, I would expect that the source file would be copied into the destination directory, with the same name that it had before (i.e. the last part at the end of the src
path string).
However, it seems that, instead, copy()
attempts to replace the dest
directory with the src
file.
I have tried {clobber: false}
but this simply seems to stop the copy operation from taking place [as per your explanation in #321 I now understand why].
To get it to behave as desired, I have to include the destination filename at the end of the dest
path. This means duplicating the destination filename. Sometimes, my code that calls copy()
does not know the filename (only the full src
path), so it is necessary to make an extra call, to path.basename()
, first.
I assume that this behaviour is by design to fit in with how (standard) fs
works? However I wonder if you could add a further copy()
-like function (or option on the fs-extra version of copy()
to support this behaviour?
Thanks for this very helpful module (only just started using it, but it’s already saved me lots of time) 😃.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
I understand the perspective here. A lot of people have requested similar functionality. It’s my belief that we as programmers should be explicit where possible. As reading code is harder than writing code.
fs-extra
has chosen to encourage this by making programmer intent obvious to those who read the code.I think where this functionality makes sense is in the case of shell programs where terse expressiveness is valued given the longevity of shell scripts.
Hope this makes sense.
You’re welcome. @RyanZim and I have a lot of great things planned for this module! 😃
@RyanZim well this is another option that is preferable sometimes. But my real example is slightly more complicated than I have shared before
There I would go with three
copyFileSync
calls instad of creating{src, dest}
object pairs and iterating over them.