如何将NTFS元数据添加到任何文件?

如何解决如何将NTFS元数据添加到任何文件?

是否可以向TXT文件添加“ Version = 1.2.3.4”之类的信息? NTFS元数据可以实现吗?如果可以,我可以通过程序设置此类信息吗?

在此先感谢您的提示!伯恩德

解决方法

您可以使用备用数据流(ADS)或扩展文件属性(more e.g. here)。

如果您确定文件保留在NTFS上,则备用数据流是存储任何数量备用数据的理想方法-但是当此类文件离开NTFS时,您将丢失ADS。

另一种选择是使用扩展文件属性,它受支持跨平台,跨FS,但有局限性(例如,可以存储多少数据)。如果您要保存例如版本信息,这可能是最好的方法。

,

谢谢罗伯特!我使用了您建议的NTFS的扩展文件属性。它们称为“文件摘要信息”。不幸的是,Windows文件资源管理器的“详细信息”选项卡中的文本文件没有显示信息-可以说-。我为注册表找到了一些技巧,但它们还没有起作用。我的代码是Delphi:

CONST FmtID_SummaryInformation:TGUID=   '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';
//    FMTID_DocSummaryInformation:TGUID='{D5CDD502-2E9C-101B-9397-08002B2CF9AE}';
//    FMTID_UserDefinedProperties:TGUID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}';
      IID_IPropertySetStorage:TGUID=    '{0000013A-0000-0000-C000-000000000046}';

      STGFMT_FILE=3; //Indicates that the file must not be a compound file.
                      //This element is only valid when using the StgCreateStorageEx
                      //or StgOpenStorageEx functions to access the NTFS file system
                      //implementation of the IPropertySetStorage interface.
                      //Therefore,these functions return an error if the riid
                      //parameter does not specify the IPropertySetStorage interface,//or if the specified file is not located on an NTFS file system volume.

      STGFMT_ANY=4; //Indicates that the system will determine the file type and
                    //use the appropriate structured storage or property set
                    //implementation.
                    //This value cannot be used with the StgCreateStorageEx function.


      // Summary Information
       PID_TITLE        = 2;
       PID_SUBJECT      = 3;
       PID_AUTHOR       = 4;
       PID_KEYWORDS     = 5;
       PID_COMMENTS     = 6;
       PID_TEMPLATE     = 7;
       PID_LASTAUTHOR   = 8;
       PID_REVNUMBER    = 9;
       PID_EDITTIME     = 10;
       PID_LASTPRINTED  = 11;
       PID_CREATE_DTM   = 12;
       PID_LASTSAVE_DTM = 13;
       PID_PAGECOUNT    = 14;
       PID_WORDCOUNT    = 15;
       PID_CHARCOUNT    = 16;
       PID_THUMBNAIL    = 17;
       PID_APPNAME      = 18;
       PID_SECURITY     = 19;
(*
       // Document Summary Information
       PID_CATEGORY     = 2;
       PID_PRESFORMAT   = 3;
       PID_BYTECOUNT    = 4;
       PID_LINECOUNT    = 5;
       PID_PARCOUNT     = 6;
       PID_SLIDECOUNT   = 7;
       PID_NOTECOUNT    = 8;
       PID_HIDDENCOUNT  = 9;
       PID_MMCLIPCOUNT  = 10;
       PID_SCALE        = 11;
       PID_HEADINGPAIR  = 12;
       PID_DOCPARTS     = 13;
       PID_MANAGER      = 14;
       PID_COMPANY      = 15;
       PID_LINKSDIRTY   = 16;
       PID_CHARCOUNT2   = 17;
*)
FUNCTION IsNTFS(AFileName:AnsiString):Boolean;
VAR fso,drv:OleVariant;
BEGIN
  fso:=CreateOleObject('Scripting.FileSystemObject'{=});
  drv:=fso.GetDrive(fso.GetDriveName(AFileName));
  Result:=drv.FileSystem='NTFS'{=};
END;

FUNCTION StgOpenStorageEx(
 CONST pwcsName:POleStr;   //Pointer to the path of the
                           //file containing storage object
       grfMode:LongInt;    //Specifies the access mode for the object
       stgfmt:DWORD;       //Specifies the storage file format
       grfAttrs:DWORD;     //Reserved; must be zero
       pStgOptions:Pointer;//Address of STGOPTIONS pointer
       reserved2:Pointer;  //Reserved; must be zero
       riid:PGUID;         //Specifies the GUID of the interface pointer
       OUT stgOpen:IStorage//Address of an interface pointer
) : HResult; stdcall; external 'ole32.dll'{=};

FUNCTION GetFileSummaryInfo(FileName:AnsiString):AnsiString;
{Read the File Summary Info of a file (NTFS)}
  FUNCTION PropertyPIDToCaption(CONST ePID:Cardinal):AnsiString;
  BEGIN {PropertyPIDToCaption}
    CASE ePID OF
      PID_TITLE:       Result:='Title';
      PID_SUBJECT:     Result:='Subject';
      PID_AUTHOR:      Result:='Author';
      PID_KEYWORDS:    Result:='Keywords';
      PID_COMMENTS:    Result:='Comments';
      PID_TEMPLATE:    Result:='Template';
      PID_LASTAUTHOR:  Result:='Last Saved By';
      PID_REVNUMBER:   Result:='Revision Number';
      PID_EDITTIME:    Result:='Total Editing Time';
      PID_LASTPRINTED: Result:='Last Printed';
      PID_CREATE_DTM:  Result:='Create Time/Date';
      PID_LASTSAVE_DTM:Result:='Last Saved Time/Date';
      PID_PAGECOUNT:   Result:='Number of Pages';
      PID_WORDCOUNT:   Result:='Number of Words';
      PID_CHARCOUNT:   Result:='Number of Characters';
      PID_THUMBNAIL:   Result:='Thumbnail';
      PID_APPNAME:     Result:='Creating Application';
      PID_SECURITY:    Result:='Security';
      ELSE             Result:='$'+IntToHex(ePID,8);
    END
  END; {PropertyPIDToCaption}
VAR i,k:Integer;
    PropSetStg:IPropertySetStorage;
    PropSpec:ARRAY OF TPropSpec;
    PropStg:IPropertyStorage;
    PropVariant:ARRAY OF TPropVariant;
    Rslt:HResult;
    S:AnsiString;
    Stg:IStorage;
    PropEnum:IEnumSTATPROPSTG;
    HR:HResult;
    PropStat:STATPROPSTG;
    AHRes:HRESULT;
    PFNw,P:PWideChar;
BEGIN {GetFileSummaryInfo}
  GetMem(P,257); PFNw:=StringToWideChar(FileName,P,256);
  Result := '';
  TRY
    OleCheck(StgOpenStorageEx(PFNw,STGM_READ OR STGM_SHARE_DENY_WRITE,STGFMT_FILE,NIL,@IID_IPropertySetStorage,Stg));
    PropSetStg:=Stg AS IPropertySetStorage;
    AHRes:=PropSetStg.Open(FmtID_SummaryInformation,STGM_READ OR STGM_SHARE_EXCLUSIVE,PropStg);
    IF AHRes<>S_OK THEN Exit;
    OleCheck(AHRes);
    OleCheck(PropStg.Enum(PropEnum));
    hr:=PropEnum.Next(1,PropStat,NIL);
    i:=0;
    WHILE hr=S_OK DO BEGIN
      inc(i);
      SetLength(PropSpec,I);
      PropSpec[i-1].ulKind:=PRSPEC_PROPID;
      PropSpec[i-1].propid:=PropStat.propid;
      hr := PropEnum.Next(1,nil);
    END;
    SetLength(PropVariant,i);
    Rslt:=PropStg.ReadMultiple(i,@PropSpec[0],@PropVariant[0]);
    IF Rslt=S_FALSE THEN Exit;
    FOR k:=0 TO i-1 DO BEGIN
      S:='';
      IF (PropVariant[k].vt=VT_LPWSTR) AND Assigned(PropVariant[k].pwszVal) THEN
        S:=WideCharToString(PropVariant[k].pwszVal);
      IF (PropVariant[k].vt=VT_LPSTR) AND Assigned(PropVariant[k].pszVal) THEN
        S:=PropVariant[k].pszVal;
      S:=PropertyPIDToCaption(PropSpec[k].Propid)+'='+S;
      IF S<>'' THEN Result:=Result+S+#13#10;
    END;
  FINALLY
  END;
END; {GetFileSummaryInfo}

PROCEDURE SetFileSummaryInfo(FileName,Author,Title,Subject,Keywords,Comments:AnsiString);
{Write some fields of the File Summary Info of a file (NTFS)}
VAR PropSetStg:IPropertySetStorage;
    PropSpec:ARRAY OF TPropSpec;
    PropStg:IPropertyStorage;
    PropVariant:ARRAY OF TPropVariant;
    Stg:IStorage;
    PFNw,P:PWideChar;
    Anz:LongInt;
BEGIN {SetFileSummaryInfo}
  IF NOT IsNTFS(FileName) THEN Exit;
  Anz:=5;
  GetMem(P,256);
  OleCheck(StgOpenStorageEx(PFNw,STGM_SHARE_EXCLUSIVE OR STGM_READWRITE,STGFMT_ANY,Stg));
  PropSetStg:=Stg AS IPropertySetStorage;
  OleCheck(PropSetStg.Create(FmtID_SummaryInformation,FmtID_SummaryInformation,PROPSETFLAG_DEFAULT,STGM_CREATE OR STGM_READWRITE OR STGM_SHARE_EXCLUSIVE,PropStg));
  Setlength(PropSpec,Anz);
  PropSpec[0].ulKind:=PRSPEC_PROPID;
  PropSpec[0].propid:=PID_AUTHOR;
  PropSpec[1].ulKind:=PRSPEC_PROPID;
  PropSpec[1].propid:=PID_TITLE;
  PropSpec[2].ulKind:=PRSPEC_PROPID;
  PropSpec[2].propid:=PID_SUBJECT;
  PropSpec[3].ulKind:=PRSPEC_PROPID;
  PropSpec[3].propid:=PID_KEYWORDS;
  PropSpec[4].ulKind:=PRSPEC_PROPID;
  PropSpec[4].propid:=PID_COMMENTS;
  SetLength(PropVariant,Anz);
  PropVariant[0].vt:=VT_LPSTR;
  PropVariant[0].pszVal:=PChar(Author);
  PropVariant[1].vt:=VT_LPSTR;
  PropVariant[1].pszVal:=PChar(Title);
  PropVariant[2].vt:=VT_LPSTR;
  PropVariant[2].pszVal:=PChar(Subject);
  PropVariant[3].vt:=VT_LPSTR;
  PropVariant[3].pszVal:=PChar(Keywords);
  PropVariant[4].vt:=VT_LPSTR;
  PropVariant[4].pszVal:=PChar(Comments);
  OleCheck(PropStg.WriteMultiple(Anz,@PropVariant[0],2));
  PropStg.Commit(STGC_DEFAULT);
  FreeMem(P);
END; {SetFileSummaryInfo}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-