gpt4 book ai didi

c# - 我可以安全地在文件夹上使用 `IO.File.GetAttributes` 吗?

转载 作者:行者123 更新时间:2023-11-30 22:33:50 26 4
gpt4 key购买 nike

我的 C# 代码使用以下两个片段检测文件和文件夹属性的变化:

// For files
return (IO.File.GetAttributes(Source) != IO.File.GetAttributes(Dest))

// For folders
IO.DirectoryInfo SourceInfo = new IO.DirectoryInfo(AbsSource);
IO.DirectoryInfo DestInfo = new IO.DirectoryInfo(AbsDest);
return (SourceInfo.Attributes != DestInfo.Attributes);

我注意到 IO.File.GetAttributes 似乎也适用于文件夹文件夹,所以我想知道我是否可以删除特定于目录的部分并只对两者使用单行文件和文件夹。

这可能吗?读取 IO.DirectoryInfo.Attributes 是否等同于调用 File.GetAttributes

谢谢!

最佳答案

是的,同样的事情。您可以从类继承中看出。 FileInfo 和 DirectoryInfo 类都继承了抽象 FileSystemInfo 类的非抽象属性。

关于c# - 我可以安全地在文件夹上使用 `IO.File.GetAttributes` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8110646/

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