【问题标题】:How do I record the name of the files in a folder? [duplicate]如何记录文件夹中文件的名称? [复制]
【发布时间】:2013-04-12 08:37:03
【问题描述】:

例如我有:
文件目录:C:\Users\Desktop\program
目录中的文件:奶酪(文件夹)、蔬菜(txt 文件)、肉类(doc 文件)
如何记录目录中文件和文件夹的名称? 提前致谢!!

【问题讨论】:

标签: windows perl


【解决方案1】:

另一种方式是使用glob:

my @files = <*>;

这将为您提供当前目录中的所有文件。

如果您只想查找某些文件,此方法很方便:

my @jpegs = <*.jpg>;

如果那不是您想要的目录,change to the current directory 或包含路径:

my @files = </foo/bar*>;

请注意,即使在 Windows 上执行此操作,您也应该 use forward slashes

【讨论】:

    【解决方案2】:

    尝试以下方法:

    opendir FOLDER, $folder or die "Cant open folder $folder: $!";
    my @file= readdir FOLDER;
    closedir FOLDER;
    

    【讨论】:

    • 谢谢!!另一个问题,我如何在txt文件中打印结果?
    • @user2297543 另一个问题 - 另一个问题 ;) 不,不要那样做,只看perldoc
    猜你喜欢
    • 2014-09-02
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 2018-09-06
    • 1970-01-01
    • 2021-05-15
    • 2021-12-28
    相关资源
    最近更新 更多