malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.23k stars 30 forks source link

MOVE the content of directory to directory which is not exist will move the contents of subdirectories of original path to new one #84

Closed aleaksunder closed 3 years ago

aleaksunder commented 3 years ago

Hello! Just hit another issue with MOVE Assuming we have such a tree:

C:.
└───temp
    ├───dir1
    │   ├───subdir1
    │   │       file1
    │   │
    │   └───subdir2
    │           file2
    │
    └───dirExist

then I tried to move the contents of folder dir1 to existen dir dirExist:

YORI> move "c:\temp\dir1\*" "c:\temp\dirExist"

and all is fine here:

C:.
└───temp
    ├───dir1
    └───dirExist
        ├───subdir1
        │       file1
        │
        └───subdir2
                file2

But when revert all back and tried to move the contents of dir1 to not existen directory:

move "c:\temp\dir1\*" "c:\temp\dirNew"

it fails with message: Attempting to move multiple files over a single file (\\?\C:\temp\dirNew) and after that the tree became this:

C:.
└───temp
    │
    ├───dir1
    │   └───subdir2
    │           file2
    │
    ├───dirExist
    └───dirNew
            file1

And all is fine with COPY in both cases... even copy -s "dir1\*" "dirNew" creates new "dirNew" and copies all contents of "dir1"

malxau commented 3 years ago

copy -s creates the directory. copy without -s has the same behavior as move - if multiple files are in the source, it will error trying to copy the second file over the first. move is in a bit of a mind because there's no such thing as move -s, since it is always a non-recursive operation, even if it has hierarchical effects.

Although it's always easy to pick an example that makes the behavior look illogical, see how we got here - move src dest is a valid thing to do to a single file, where dest is a newly created file; move src\* dest might match a single file in which case these semantics make sense. It seems very scary to have different behavior based on the number of files that are found, since the behavior will be very hard to predict.