Copying and moving directories

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 16 09:06:30 PST 2017


On Thursday, February 16, 2017 16:47:05 Chris via Digitalmars-d-learn wrote:
> On Thursday, 16 February 2017 at 16:41:48 UTC, Adam D. Ruppe
>
> wrote:
> > On Thursday, 16 February 2017 at 16:38:51 UTC, Chris wrote:
> >> In `std.file`, I haven't found a function that allows me to
> >> move or at least copy directories, as in `mv dir /toDir`. Do I
> >> have to go the awkward way over `rename` or something?
> >
> > Have you already tried just renaming the directory?
>
> Yes, but that's a bit awkward. It'd be handier to have a function
> like `mv(dir, toDir)`.

Well, there's zero difference between renaming the file or directory and
moving it. It's simply a difference in name. rename actually comes from
POSIX, where rename is used in C code, and mv is used in the shell. So, I
guess that you can blame POSIX. But there really isn't any reason to have a
mv or move function in addition to rename.

If you want mv instead, just alias rename to mv.

However, I would point out that rename has the problem (at least on *nix -
not sure about Windows) that it can't move across filesystem boundaries. I
think that at some point, an alternative which did work across filesystem
boundaries was proposed, and that may have been called move. It's not
currently in Phobos though.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list