Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving files on different volumes in .NET

Apparently I can't move files on different volumes using Directory.Move.

I have read that I have to copy each file individually to the destination, then delete the source directory.

Do I have any other option?

like image 286
Blankman Avatar asked Dec 18 '08 16:12

Blankman


People also ask

How do I move multiple files from one directory to another in C#?

First get all the files with specified extension using Directory. GetFiles() and then iterate through each files in the list and move them to target directory. Show activity on this post. will Move all the files from Desktop to Directory " TextFiles ".

How do I move a file to a different directory?

Right-click the file or folder you want, and from the menu that displays click Move or Copy. The Move or Copy window opens. Scroll down if necessary to find the destination folder you want. If you need to, click on any folder you see to access its subfolders.

How do I move a file in C#?

Move() is an inbuilt File class method that is used to move a specified file to a new location. This method also provides the option to specify a new file name. Syntax: public static void Move (string sourceFileName, string destFileName);


1 Answers

Regardless of whether or not Directory.Move (or any other function) performed the move between volumes, it would essentially be doing a copy and delete anyway underneath. So if you want a speed increase, that's not going to happen. I think the best solution would be to write your own reusable move function, which would get the volume label (C:,D:) from the to and from paths, and then either perform a move, or copy+delete when necessary.

like image 109
Kibbee Avatar answered Oct 02 '22 16:10

Kibbee