如何隐藏在C#中的文件?文件

2023-09-04 00:13:02 作者:自作多情 *

我想隐藏在C#中的文件。我知道文件的路径,并可以创建FileInfo对象。

I want to hide a file in c#. I know the file path and can create a FileInfo object.

如何隐藏呢?

推荐答案

接受的答案:

File.SetAttributes(path, FileAttributes.Hidden);

将导致它可能会丢失某些其他属性,所以你应该:

will result in certain other attributes it may have being lost, so you should:

File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);