# Mv() in Windows

**URL:** <https://discourse.julialang.org/t/mv-in-windows/81904>\
**Category:** Performance\
**Tags:** doctest\
**Created:** [May 30, 2022, 8:04am UTC](https://discourse.julialang.org/t/mv-in-windows/81904 "2022-05-30T08:04:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [May 30, 2022, 8:04am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/1 "2022-05-30T08:04:46Z")

</div>

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

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

```

but get

```julia
 '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)?

---

<div class="post-metadata">

**Author:** ![Olivier\_Merchiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_merchiers/32/4073_2.png) [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)\
**Post date:** [May 30, 2022, 8:16am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/2 "2022-05-30T08:16:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [May 30, 2022, 8:23am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/3 "2022-05-30T08:23:44Z")

</div>

Sorry about the mess – you were too fast!

---

<div class="post-metadata">

**Author:** ![Olivier\_Merchiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivier_merchiers/32/4073_2.png) [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)\
**Post date:** [May 30, 2022, 8:33am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/4 "2022-05-30T08:33:07Z")

</div>

No problem!

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 30, 2022, 9:06am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/5 "2022-05-30T09:06:54Z")

</div>

You can use `readdir` to accomplish this:

```julia
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.

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [May 30, 2022, 9:18am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/6 "2022-05-30T09:18:24Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 30, 2022, 9:22am UTC](https://discourse.julialang.org/t/mv-in-windows/81904/7 "2022-05-30T09:22:19Z")

</div>

> [@Philippe\_Maincon1](#):
>
> Thanks - so indeed, you move each file for itself explicitely.

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).
