可以向 NTFS 文件夹添加自定义属性吗?

发布于 2024-10-02 09:00:39 字数 140 浏览 0 评论 0原文

我希望能够将自己的自定义数据/属性添加到 NTFS 上的现有文件夹中,这样如果移动文件夹,属性也会随之移动。一种解决方案是在文件夹中存储一个文件来包含我需要或想要的任何内容。

我特别感兴趣的是是否有一种方法可以将自定义属性添加到目录文件系统对象本身。

I would like to be able to add my own custom data/properties to existing folders on NTFS, so that if a folder is moved, the properties move with it. One solution would be to store a file within the folder to contain whatever I need or want.

What I am particularly interested in, is whether or not there is a way to add custom properties to the directory file system object itself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风苍溪 2024-10-09 09:00:39

如果您感觉勇敢(或愚蠢),也许有一个替代方案数据流将是一种替代方案。

我不确定是否可以应用于目录而不是普通文件,并且它充满了需要考虑的问题:

  1. 没有标准的 Windows 用户工具列出它们(例如无法从资源管理器或 cmd 提示符查看,但可以在大多数程序中以正确的名称打开)。
  2. 它们无法很好地从 NTFS 文件系统转移出去。
  3. 他们可能还会举起一些 AV 标志,我不知道。

快乐编码。

If you are feeling brave (or foolish) perhaps an Alternative Data Stream would be an alternative.

I am not sure if can be applied to a directory as opposed to a normal file and it's littered with concerns that need to be considered:

  1. There are no standard windows user tool that lists them (e.g. can't view from explorer or cmd prompt, but can be opened in most programs given correct name).
  2. They will not transfer off of the NTFS filesystem well.
  3. They may also raise some AV flags, I do not know.

Happy coding.

萌逼全场 2024-10-09 09:00:39

这是 C# 中显示文件自定义属性的方法

DSOFile.OleDocumentPropertiesClass file = new DSOFile.OleDocumentPropertiesClass();

file.Open(@"C:\setup.exe", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

string key = "key1";

object value = "value1";

// Adds new custom property.

file.CustomProperties.Add(key, ref value);

// Go through existing custom properties.

foreach (DSOFile.CustomProperty p in file.CustomProperties)

{
Console.WriteLine("{0}:{1}", p.Name, p.get_Value().ToString());
}

file.Close(true);

首先在 file.CustomProperties.Add(key, ref value); 中
通过修改属性key(property),就可以修改它,这里有以下内容。
在 key 中,您应该放置以下 attribute_names 之一,这些属性名称在这里通过其实际值的名称描述为常量

Const FILE_ATTRIBUTE_READONLY = 1
Const FILE_ATTRIBUTE_HIDDEN = 2
Const FILE_ATTRIBUTE_SYSTEM = 4
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_ENCRYPTED = &H40
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Const FILE_ATTRIBUTE_SPARSE_FILE = &H200
Const FILE_ATTRIBUTE_REPARSE_POINT = &H400
Const FILE_ATTRIBUTE_COMPRESSED = &H800
Const FILE_ATTRIBUTE_OFFLINE = &H1000
Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000 

然后您应该将所需的值分配给常量,在 value 中

然后查看每个文件的每个属性,它会在行上显示它们

Console.WriteLine("{0}:{1}", p.Name, p.get_Value().ToString());

Here is a way in c# to show file custom properties

DSOFile.OleDocumentPropertiesClass file = new DSOFile.OleDocumentPropertiesClass();

file.Open(@"C:\setup.exe", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

string key = "key1";

object value = "value1";

// Adds new custom property.

file.CustomProperties.Add(key, ref value);

// Go through existing custom properties.

foreach (DSOFile.CustomProperty p in file.CustomProperties)

{
Console.WriteLine("{0}:{1}", p.Name, p.get_Value().ToString());
}

file.Close(true);

First in file.CustomProperties.Add(key, ref value);
by modifying the attribute key(the property, you can modify it, here are the following.
in key you should put one of the following attribute_names, that are here described as constants by names from their real values

Const FILE_ATTRIBUTE_READONLY = 1
Const FILE_ATTRIBUTE_HIDDEN = 2
Const FILE_ATTRIBUTE_SYSTEM = 4
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_ENCRYPTED = &H40
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Const FILE_ATTRIBUTE_SPARSE_FILE = &H200
Const FILE_ATTRIBUTE_REPARSE_POINT = &H400
Const FILE_ATTRIBUTE_COMPRESSED = &H800
Const FILE_ATTRIBUTE_OFFLINE = &H1000
Const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000 

Then you should assign the desired value to the constant, in value

Then to see each properties of each file it show them on the line

Console.WriteLine("{0}:{1}", p.Name, p.get_Value().ToString());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文