.NET Directory.Move() vs File.Move()

Eric

We have an application that stores files in a temporary location until the user decides to finalize their transaction. The temp directory is unique for each transaction. Once they do finalize, the files are moved from the temp location to a final location, which is also unique for each transaction. This is all working without any issues.

I'm rather surprised, but when searching Google and SO, we were unable to find any topics on which is generally considered a best practice:

  1. Call System.IO.Directory.Move(src, des) to simply move the whole directory at once, or
  2. Call System.IO.File.Move(src, des) to move the files one at a time.

As these decisions typically rely on a number of factors, I should note the following conditions:

  1. The source and destination directories will always be on the same machine, but the application making the calls will be on a different machine on the same network. I believe the application server and file server are separate VM's on the same physical machine, but I am not positive.
  2. The number of files could range from 1 to 10, or more. I do not monitor the production system myself, so I am unsure of the average file count, or how spread the count is.
MicroVirus

I think the biggest issue is not speed but rather: what happens on a move error?

I'm going to use the information in LukeH's answer rather than repeating it here.

The behaviour of MoveFile for a directory move should be appropriate for if it fails to move a single file. If you use a per file move, then you have to handle the error conditions yourself in an appropriate manner. This requires some careful thought.

Note that the documentation of MoveFile specifies that:

The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.

That might or might not be an issue for you and reason to use a per-file Move. The Directory.Move documentation explicitly mentions this (and the reference source for Directory.Move explicitly checks for source and destination having the same root).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Move every file that is not a directory

From Dev

Move File in parent directory

From Dev

Move file to relative parent directory

From Dev

Command to move a file to a directory even if the directory is not present

From Dev

Move directory to

From Dev

move_uploaded_file / No such file or directory in PHP

From Dev

Move a file to another Ftp directory and rename it

From Dev

Make directories incrementally, move file into directory - loop

From Dev

Mass file+folder+directory move

From Dev

Move file to local ANT lib directory?

From Dev

How to move a file from a default directory to another?

From Dev

How to find a specific file and move it to a specific directory?

From Dev

Make directories incrementally, move file into directory - loop

From Dev

Move a list of files(in a text file) to a directory?

From Dev

Move each file into its parent directory in linux

From Dev

if the file is a directory don't move it mv bash

From Dev

PHP move_uploaded_file for a directory uploaded

From Dev

How to move file from directory A to directory B in remote server?

From Dev

How to move file from directory A to directory B in remote server?

From Dev

Shell Script to move oldest file from one directory to another directory

From Dev

Does .NET File.Move copy and then delete

From Dev

Windows Batch File: Look for directory, if not exist, create, then move file to it

From Dev

move_uploaded_file(...): failed to open stream: No such file or directory

From Dev

Windows Batch File: Look for directory, if not exist, create, then move file to it

From Dev

How to move a directory, file by file? (instead of "copy then remove")

From Dev

move_uploaded_file: no such file when another directory is used

From Dev

When I move a file to a different directory on the same partition, does the file's data actually move on disk?

From Dev

How to move GitHub directory

From Dev

rewrite move up directory

Related Related

  1. 1

    Move every file that is not a directory

  2. 2

    Move File in parent directory

  3. 3

    Move file to relative parent directory

  4. 4

    Command to move a file to a directory even if the directory is not present

  5. 5

    Move directory to

  6. 6

    move_uploaded_file / No such file or directory in PHP

  7. 7

    Move a file to another Ftp directory and rename it

  8. 8

    Make directories incrementally, move file into directory - loop

  9. 9

    Mass file+folder+directory move

  10. 10

    Move file to local ANT lib directory?

  11. 11

    How to move a file from a default directory to another?

  12. 12

    How to find a specific file and move it to a specific directory?

  13. 13

    Make directories incrementally, move file into directory - loop

  14. 14

    Move a list of files(in a text file) to a directory?

  15. 15

    Move each file into its parent directory in linux

  16. 16

    if the file is a directory don't move it mv bash

  17. 17

    PHP move_uploaded_file for a directory uploaded

  18. 18

    How to move file from directory A to directory B in remote server?

  19. 19

    How to move file from directory A to directory B in remote server?

  20. 20

    Shell Script to move oldest file from one directory to another directory

  21. 21

    Does .NET File.Move copy and then delete

  22. 22

    Windows Batch File: Look for directory, if not exist, create, then move file to it

  23. 23

    move_uploaded_file(...): failed to open stream: No such file or directory

  24. 24

    Windows Batch File: Look for directory, if not exist, create, then move file to it

  25. 25

    How to move a directory, file by file? (instead of "copy then remove")

  26. 26

    move_uploaded_file: no such file when another directory is used

  27. 27

    When I move a file to a different directory on the same partition, does the file's data actually move on disk?

  28. 28

    How to move GitHub directory

  29. 29

    rewrite move up directory

HotTag

Archive