这是一个有趣的一个。我的代码在最后。
我对自定义文件属性并不十分熟悉,但是下面将遍历所有属性,并在遇到连续两个空格或所需的键时停止。运行它时,您会发现它没有列出定制属性,因为它不能通过此接口获得。
这是基于代码的How to get the details of a file on Windows
use strict;
use warnings;
use Win32::OLE;
my $fileName = 'test.txt';
my $myDir = 'c:\testing\e';
my $objShell = Win32::OLE->new('Shell.Application') or die;
my $objFolder = $objShell->NameSpace($myDir) or die;
my $objFile = $objFolder->ParseName($fileName) or die;
my $blank = 0;
# Apparently the numbers vary between OS versions, 300 is a guess
for (my $i = 0; $i < 300; $i++) {
my $propertyName = $objFolder->GetDetailsOf($fileName, $i);
# skip when finding 2 blanks in a row, there may be a few more later.
if ($propertyName eq '') {
if ($blank) {
last;
}
$blank = 1;
next;
}
my $propertyValue = $objFolder->GetDetailsOf($objFile, $i);
print "$i -- $propertyName -- $propertyValue\n";
}
所以,看遍互联网后,我不认为这是可能使用普通的Windows API调用(我可能是非常错误的事情)。
此链接显示,你可以从微软为了下载DSOFile.dll
访问自定义属性:http://blog.rodhowarth.com/2008/06/how-to-set-custom-attributes-file.html
我试过下面的Perl代码,它似乎工作。我没有深入研究Win32::OLE
文档 - 可能有更好的方法来访问信息,而不是直接进行哈希查找。
use strict;
use warnings;
use Win32::OLE;
use Data::Dumper;
my $obj = Win32::OLE->new('DSOFile.OleDocumentProperties') or die Win32::OLE->LastError;
$obj->Invoke('Open', 'C:\testing\e\test.txt', 0, 0); # constants found in headers
my $custom_property = $obj->{CustomProperties}{'myprop'}; # you would use 'email' here
my $custom_value = $custom_property->{'Value'};
print "Value is: $custom_value\n";
print "\nFile Object:\n", Dumper $obj;
print "\nCustom Property:\n", Dumper $custom_property;
您也可以直接使用该DLL,但这往往是非常痛苦的,所以最好避免。
感谢尼克, 我已经尝试了第一种方法,并且无法检索我的属性。对不起,我应该在问题中提到。 我已经从微软下载了DLL,将它粘贴在我的perl文件所在的相同位置。但是脚本在 失败,my $ obj = Win32 :: OLE-> new('DSOFile.OleDocumentProperties')或死于'错误'; –
您需要使用安装程序,以便您的注册表得到更新并知道DSOFile.OleDocumentProperties –
安装程序只是提取其内容。它没有做别的。 我已经使用regsvr32来手动注册dll,甚至perl脚本死于那个新的()行消息“死于行......“ 感谢您的帮助,我会尝试挖掘一段时间,然后回来 –