Perl - 获取文件项目

博客提供了关于Perl目录的参考链接http://www.runoob.com/perl/perl-directories.html,还提及返回JSON格式的文件列表,并给出转载来源https://my.oschina.net/wffger/blog/3024865。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:http://www.runoob.com/perl/perl-directories.html

下面返回JSON格式的文件列表

#!/usr/bin/perl

use strict;
use warnings;
use utf8;
use feature ':5.26';


require File::Find;

# 宣告 STDOUT, STDIN, STDERR 都使用

# UTF-8 編碼方式。

binmode(STDOUT, ":encoding(utf8)");
binmode(STDIN, ":encoding(utf8)");
binmode(STDERR, ":encoding(utf8)");

# 用來顯示資料夾資訊的回呼函式。
sub callback {
  unless (-d) {
    print "檔案所在目錄的絕對路徑:$File::Find::dir\n";
    print "檔案所在位置的絕對路徑:$File::Find::name\n";
    print "檔案名稱:$_\n";
  };
};

# 用來顯示資料夾資訊的回呼函式。
sub fileList {
  unless (-d) {
    print "{\"path\":\"$File::Find::dir\",\"name\":\"$_\"}\n";
  };
};

my @recursiveFolder = qw(/home/ydx/Documents/Project/Perl-Practice);
# Let's recursive it!
# File::Find::find(\&callback, @recursiveFolder);

File::Find::find(\&fileList, @recursiveFolder);

 

转载于:https://my.oschina.net/wffger/blog/3024865

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值