开发者

Does IO.File.Copy replicate files attributes?

Does the IO.File.Copy method preserve file attributes? Especially, if I have a write-protected file, will the copy be w开发者_Python百科rite-protected to?


The following code proves that 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 having just used Reflector I see that IO.File.Copy uses kernel32.dll's CopyFile function which has documentation of what is copied and what is not: http://msdn.microsoft.com/en-us/library/aa363851(VS.85).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜