Is IO.File.Copy replication of file attributes?

Does the IO.File.Copy method IO.File.Copy file attributes? Especially if I have a write-protected file, will the copy be write-protected?

+4
source share
1 answer

The following code proves that the file attributes are copied.

  Dim sourceFile = "z.txt" Dim destinationFile = "x.txt" Using sw As IO.StreamWriter = IO.File.CreateText(sourceFile) sw.Write("testing") End Using IO.File.SetAttributes(sourceFile, IO.FileAttributes.ReadOnly) Debug.WriteLine("Source File ReadOnly = " & (IO.File.GetAttributes(sourceFile) And IO.FileAttributes.ReadOnly)) IO.File.Copy(sourceFile, destinationFile) Debug.WriteLine("Destination File ReadOnly = " & (IO.File.GetAttributes(destinationFile) And IO.FileAttributes.ReadOnly)) 

And just using Reflector, I see that IO.File.Copy uses the CopyFile function from kernel32.dll, which has documentation about what is copied and what is not: http://msdn.microsoft.com/en-us/ library / aa363851 (VS.85) .aspx

+4
source

Source: https://habr.com/ru/post/1309635/


All Articles