Recent

Author Topic: How can I add NTFS metadata to any file?  (Read 2643 times)

Bernd82

  • New Member
  • *
  • Posts: 30
How can I add NTFS metadata to any file?
« 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

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: How can I add NTFS metadata to any file?
« Reply #1 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 (the code is in the au3 files) or this "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.

Bernd82

  • New Member
  • *
  • Posts: 30
Re: How can I add NTFS metadata to any file?
« Reply #2 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.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: How can I add NTFS metadata to any file?
« Reply #3 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.

Bernd82

  • New Member
  • *
  • Posts: 30
Re: How can I add NTFS metadata to any file?
« Reply #4 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".

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How can I add NTFS metadata to any file?
« Reply #5 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
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Bernd82

  • New Member
  • *
  • Posts: 30
Re: How can I add NTFS metadata to any file?
« Reply #6 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"?!?

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: How can I add NTFS metadata to any file?
« Reply #7 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.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Bernd82

  • New Member
  • *
  • Posts: 30
Re: How can I add NTFS metadata to any file?
« Reply #8 on: September 25, 2020, 12:14:44 am »
Thanks for the hint!

 

TinyPortal © 2005-2018