Mv() in Windows

I have two directories A and B(preexisting, with files in them) and I want to move, or copy the files inside A to B - without loosing previous content of B. So I type

mv(A*"\\*",B)

but get

 'B' exists. `force=true` is required to remove 'B' before moving.

And if I use that option, B gets deleted.
Any clever solution (beside copying/moving the files/folders inside A individualy)?

Hi,
I saw your previous question about deleting a post. I was answering to that one. I had to edit so it would make sense.

I think, unless your post contains some insults, degrading comments or inflamatory language I would recommend not to delete a post but just make a new one to avoid this kind of confusions.

Best
Olivier

Sorry about the mess – you were too fast!

No problem!

You can use readdir to accomplish this:

shell> ls -R
.:
A  B

./A:
C  file1  file2

./A/C:
test3

./B:

julia> function mv_inner(A, B)
           for f in readdir(A)
              mv(joinpath(A, f), joinpath(B, f))
           end
       end
mv_inner (generic function with 1 method)

julia> mv_inner("A","B")

shell> ls -R
.:
A  B

./A:

./B:
C  file1  file2

./B/C:
test3

readdir will read the files & directories of the given path and mv can already work with those. Using joinpath is preferred over string concatenation, as it is platform aware and will work across platforms.

Also, Julia is not a shell - globbing via * in a string is not a thing.

Thanks - so indeed, you move each file for itself explicitely.

Good point about “joinpath” - I will correct my code!

Even if mv would already handle that case internally, it would still have to move files individually, due to the nature of how filesystems work - they’re graph structures flattened to some representation on a disk, you can’t just move a “block of data” and keep it coherent (well, you can, but that’s a different operation than just moving some pointers in the file system around, which is all that “files in a directory” usually are under the hood).

1 Like