如何将文件夹中的文件名收集到列表中?
我正在寻找一种使用 Perl 将文件名收集到列表中的方法。例如,我进入一个包含一百个不同文件名(从文本文件到 MP3)的文件夹,我想将每个文件名放在一个列表中。我该怎么做呢?我到处寻找,似乎无法弄清楚。我已经使用了 chdir 函数,但我似乎无法读取文件名并打印它们。有人可以帮忙吗?
I am looking for a way to collect filenames into a list with Perl. For example, I go into a folder with a hundred different filenames ranging from text files to MP3, and I would like to put each and every filename in a list. How would I do that? I was looking everywhere and cannot seem to figure it out. I have gotten as far as using the chdir
function but I can't seem to read the filenames and print them. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查找函数glob:
Look for the function glob:
一种方法是打开当前目录,并获取其所有内容,例如:
显然您可以使用 grep
来获取特定类型的文件等。
One way is to open the current dir, and get all its contents, something like:
obviously you can use
grep
liketo get specific types of files, etc.