C # File.Move vs Rename - does it really move the file or just rename it?

After reading this, https://stackoverflow.com/a/166012/2102 about how to β€œrename” a file, the solution turned out to use the Files.Move or Directory.Move methods.

I know that on Windows, if I rename it, it’s instantly, since I assume that it’s not so much moving the file to disk, but somewhere the location changes with some indexing.

When I use Files.Move or Directory.Move, is it going to do the same, or is it going to make a copy and then delete?

I try to avoid the wear of my discs.

+4
source share
3 answers

Windows- .NET Framework System.IO.File.Move Win32 MoveFile.

MSDN MoveFile:

, .

, Windows Explorer. , , , /.

public static void Move(String sourceFileName, String destFileName) {
    ...
    ... 
    if (!Win32Native.MoveFile(fullSourceFileName, fullDestFileName))
    {
        __Error.WinIOError();
    } 
}
+1

, API Win32, File.Move:

MoveFile () , ( ) , . , MoveFile , . , MoveFile . . The MoveFile , .

:

, ?

, "", "", .

+5

Files.Move Directory.Move,

, . .

, , , . Windows "" , , , -. ( , ). .NET-, - , , Windows.

,

, - , . (, .) , , , , , .

Basically, software (whether it is Windows Explorer or code in the .NET Framework) tells the operating system to perform this operation. The OS informs the file system of the operation. The file system itself must be very optimized for this.

+3
source

All Articles