Home > Back-end >  How to quickly move file on network share to subfolder on same network share?
How to quickly move file on network share to subfolder on same network share?

Time:12-15

In a C# .NET 7 Core console application if you do File.Move(@"\\box\stuff\video.mkv", @"\\box\stuff\fun\video.mkv") it will do a copy and then delete on that file. But if you open Windows File Explorer and move (cut & paste) the same file it will get moved in an instant. The file I want to move is 20GB, so it's not feasible to the program to copy and delete. How can do move the file in C# .NET Core the same way File Explorer does?

The network share device is a samba server so my guess is that File Explorer does a remote move call. I simply want to list the files from the server and then move them to subfolders on the same network share.

EDIT: This is different then using any of the file dialogs from windows. This is strictly a batch process which does not require any user input or feedback.

CodePudding user response:

Instead of using File.Move, you can try using the Move method in FileInfo class.

FileInfo fileinfo = new FileInfo(filetoMovePath); 
fileinfo.MoveTo(destFileName);

This is much faster compared to static File.

Check Remarks in this MS Doc

  • Related