gpt4 book ai didi

vb.net - IO.File.Copy 是否复制文件属性?

转载 作者:行者123 更新时间:2023-12-02 09:30:18 34 4
gpt4 key购买 nike

IO.File.Copy 方法是否保留文件属性?特别是,如果我有一个写保护的文件,副本会被写保护吗?

最佳答案

下面的代码证明文件属性被复制。

    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))

刚刚使用 Reflector 后,我看到 IO.File.Copy 使用 kernel32.dll 的 CopyFile 函数,该函数包含复制内容和未复制内容的文档:http://msdn.microsoft.com/en-us/library/aa363851(VS.85).aspx

关于vb.net - IO.File.Copy 是否复制文件属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2825241/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com