问题
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.
回答1:
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:
- 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).
- They will not transfer off of the NTFS filesystem well.
- They may also raise some AV flags, I do not know.
Happy coding.
回答2:
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());
来源:https://stackoverflow.com/questions/4179784/can-one-add-custom-properties-to-ntfs-folders