Lazarus

Programming => Operating Systems => Windows => Topic started by: Bernd82 on September 02, 2020, 10:17:13 am

Title: How can I add NTFS metadata to any file?
Post by: Bernd82 on September 02, 2020, 10:17:13 am
Is there a possibility to add NTFS metadata to a file? Let's say I want to add "Version = 1.1.1.3" to a text file "hello.txt".

Any help appreciated, Bernd
Title: Re: How can I add NTFS metadata to any file?
Post by: PascalDragon on September 02, 2020, 01:49:38 pm
I assume you mean “Extended Attributes” with “NTFS Metadata”, cause the metadata of the filesystem itself is only handled by the filesystem itself. For “Extended Attributes” you need to look at NT API functions to do this, you can look at (non-Pascal) code like this (https://github.com/jschicht/EaTools) (the code is in the au3 files) or this (http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FFile%2FNtSetEaFile.html) "documentation". The involved functions are available in the unit JwaNative.

You could also simply store the information in an alternative datastream (open a file “YourFile.txt:MyData”).

In both cases you need to be aware however that the information might not survive a copying to a different filesystem (e.g. network storage). Also you need to provide some way to view them for example by writing an extension for Windows Explorer.
Title: Re: How can I add NTFS metadata to any file?
Post by: Bernd82 on September 12, 2020, 11:51:32 am

Hello PascalDragon,

thanks a lot for your answer! At the moment I used NTFS File Summary Information. I wrote about that here:

https://stackoverflow.com/questions/63701814/how-can-i-add-ntfs-metadata-to-any-file/63727869#63727869

Unfortunately the information cannot be stored on network drives, even if they seem to be NTFS and the information is not shown in Windows file explorer's context menu. I will have a look at "Extended Attributes" in the near future and write about my experiences here.
Title: Re: How can I add NTFS metadata to any file?
Post by: ASerge on September 12, 2020, 09:13:29 pm
thanks a lot for your answer! At the moment I used NTFS File Summary Information. I wrote about that here:
https://stackoverflow.com/questions/63701814/how-can-i-add-ntfs-metadata-to-any-file/63727869#63727869
In this article, you give an example of working with compound structure files that are not related to extended NTFS attributes.
Examples of such files are Microsoft *.doc (not *.docx) or *.xls (not *.xlsx) files. In such files, all data is written in several streams to a single file. They were invented back in the days of Windows 3.0! In particular, the Summary structure is used to store general information. By the way, Outlook uses it to protect attachments of the specified file types from viruses by adding a checksum (by adding additional stream) when sending them.
Of course, the developer can use the Com API to create compound files and add streams to them, in particular, the documented Summary that Explorer can display. But this will be "metadata" inside the file, not NTFS.
Title: Re: How can I add NTFS metadata to any file?
Post by: Bernd82 on September 14, 2020, 08:32:36 am
Hello all,

thanks for your hints. In the end I want to add version information to my files that is shown in the SolidWorks Product Data Management (PDM) "Tresor". Or better also in the Windows file explorer's context menu "Details".
Title: Re: How can I add NTFS metadata to any file?
Post by: avra on September 14, 2020, 10:28:14 am
If you need cross platform and file system independent way then you could use an old trick used by Dos Navigator and Total Commander, and that is to store comments for all files in a directory into single hidden file. As a bonus, both mentioned file managers also copy file comment when commented file is copied.

Here is what the file looks like:
Quote
"file1.ext" my textual description
"file2.ext" if you wish then you can store JSON or XML instead of textual description
Title: Re: How can I add NTFS metadata to any file?
Post by: Bernd82 on September 18, 2020, 11:58:05 am
Hello avra, thanks for your comment. But the hidden file will not be recognised by Windows file explorer nor by the SolidWorks Product Data Management (PDM) "Tresor"?!?
Title: Re: How can I add NTFS metadata to any file?
Post by: avra on September 18, 2020, 12:56:23 pm
the hidden file will not be recognised by Windows file explorer nor by the SolidWorks Product Data Management (PDM) "Tresor"?!?
True. You are the one who will count all the checkmarks and make a final decision. I was only pointing to an alternative cross platform solution which can work on all networks.
Title: Re: How can I add NTFS metadata to any file?
Post by: Bernd82 on September 25, 2020, 12:14:44 am
Thanks for the hint!
TinyPortal © 2005-2018