[Perl]Chilkat模块

回复
头像
paktc
出类拔萃
出类拔萃
帖子: 65
注册时间: 2016年07月21日 20:34
联系:

[Perl]Chilkat模块

帖子 paktc »

官网 http://www.chilkatsoft.com/
Chilkat 是一个跨平台的 API 接口,支持多种语言,提供网络、文本、文件系统、算法库。

其中大部分功能可免费使用(部分功能需要获得许可)

文档
示例
头像
paktc
出类拔萃
出类拔萃
帖子: 65
注册时间: 2016年07月21日 20:34
联系:

目录树遍历,以及Unicode路径名称的支持 Re: [Perl]Chilkat模块

帖子 paktc »

CkDirTree参考文档
dirTree_iterate示例
use chilkat();

$dirTree = chilkat::CkDirTree->new();

# Specify the root of the directory tree to be traversed.
$dirTree->put_BaseDir("c:/temp/abc123");

# Indicate that we want to recursively traverse the tree.
$dirTree->put_Recurse(1);

# Begin the directory tree traversal.
$success = $dirTree->BeginIterate();
if ($success != 1) {
print $dirTree->lastErrorText() . "\r\n";
exit;
}

while ($dirTree->get_DoneIterating() != 1) {

# Examine the file or directory at the current traversal position:
if ($dirTree->get_IsDirectory() == 1) {
print "(sub-directory)" . "\r\n";
}
else {
# Note: There is also a FileSize64 property...
print "Size in bytes: " . $dirTree->get_FileSize32() . "\r\n";
}

print "Relative Path: " . $dirTree->relativePath() . "\r\n";
print "Absolute Path: " . $dirTree->fullPath() . "\r\n";
print "Absolute UNC Path: " . $dirTree->fullUncPath() . "\r\n";
print "----" . "\r\n";

# Advance to the next file or sub-directory in the tree traversal.
$success = $dirTree->AdvancePosition();
if ($success != 1) {
if ($dirTree->get_DoneIterating() != 1) {
print $dirTree->lastErrorText() . "\r\n";
exit;
}
}
}
该模块支持Unicode路径名称,通过 put_Utf8 打开编码开关,将上面代码稍作修改:
use chilkat(); use File::Slurp; $dirTree = chilkat::CkDirTree->new(); $dirTree->put_BaseDir("F:/temp/UPathTest"); $dirTree->put_Recurse(1); $dirTree->put_Utf8(1); $success = $dirTree->BeginIterate(); if ($success != 1) { print $dirTree->lastErrorText() . "\r\n"; exit; } my $buff = ""; while ($dirTree->get_DoneIterating() != 1) { $buff .= $dirTree->fullPath() . "\r\n"; # Advance to the next file or sub-directory in the tree traversal. $success = $dirTree->AdvancePosition(); if ($success != 1) { if ($dirTree->get_DoneIterating() != 1) { print $dirTree->lastErrorText() . "\r\n"; exit; } } } write_file("Files.txt", {"binmode"=>":raw"}, $buff );
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客