简体   繁体   中英

How to quickly move file on network share to subfolder on same network share?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM