IO.File.Copy方法是否保留文件属性?特别是,如果我有一个写保护文件,副本是否会被写保护? 以下代码证明文件属性已复制. Dim sourceFile = "z.txt" Dim destinationFile = "x.txt" Using sw As IO.StreamWri
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