是否有perl脚本添加文件的所有者/作者姓名?
答案 0 :(得分:7)
my $owner = getpwuid((stat($file))[4]);
适用于Windows的更新,
来自这篇文章:http://www.perlmonks.org/?node_id=865219
use Win32::OLE;
my $objShell = Win32::OLE->CreateObject("Shell.Application");
my $objFolder=$objShell->Namespace("c:\\a") or die "$!" ;
my $a = $objFolder->ParseName("a.txt") or die "$!" ;
print $objFolder->GetDetailsOf($a, 8) or die "$!" ;
,或者
use Win32::Perms;
my $username = Win32::Perms->new($filename)->Owner;
答案 1 :(得分:1)
#!/usr/bin/perl -w
my @sb = stat "/etc/passwd";
my $userid = $sb[4];
my @pwent = getpwuid $userid;
my $username = $pwent[0];
print "/etc/passwd is owned by $username\n";
$ /tmp/foo.pl
/etc/passwd is owned by root
perldoc perlfunc
指南提供了有关这些功能系列的大量信息。