启用目录浏览_浏览目录

启用目录浏览

It's very simple to print a list of all files in a directory using the built-in Perl glob function. Let's look over a short script that globs and prints a list of all files, in the directory containing the script itself.

这是非常简单的打印在所有文件的清单目录中使用内置的Perl水珠功能。 让我们看一个简短的脚本,该脚本在包含脚本本身的目录中遍历并打印所有文件的列表。

Perl Glob函数的示例 ( Examples of the Perl Glob Function )

 #!/usr/bin/perl -w
@files = <*>;
foreach $file (@files) {
  print $file . "\n";
}

When you run the program, you'll see it output the filenames of all files in the directory, one per line. The glob is happening on the first line, as the <*> characters pulls the filenames into the @files array.

运行该程序时,您会看到它输出目录中所有文件的文件名,每行一个。 当<*>字符将文件名拖到@files数组中时,就会在第一行发生全局错误。

 @files = <*>;

Then you simply use a foreach loop to print out the files in the array.

然后,您只需使用foreach循环即可打印出阵列中的文件。

You can include any path in your filesystem between the <> marks. For example, say your website is in the /var/www/htdocs/ directory and you want a list of all the files:

您可以在文件系统中的<>标记之间包括任何路径。 例如,假设您的网站在/ var / www / htdocs /目录中,并且您想要所有文件的列表:

 @files = </var/www/htdocs/*>;

Or if you just want a list of the files with the extension .html:

或者,如果您只想要扩展名为.html的文件列表:

 @files = </var/www/htdocs/*.html>;

翻译自: https://www.thoughtco.com/globbing-a-directory-2641092

启用目录浏览

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值