查找具有某些扩展名的文件名

时间:2018-08-08 15:45:12

标签: perl directory

我想在目录中搜索具有以下任何扩展名的文件名:<html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>bootstrap interface</title> <link rel="stylesheet" href="css/bootstrap.css"> </head> <body> <div class="container"> <div class="row"> <div class="col-sm-4 col-md-6 col-lg-12" style="background-color: red"> <h1>Red</h1> </div> <div class="col-sm-4 col-md-6 col-lg-6" style="background-color: white"> <h1>White</h1> </div> <div class="col-sm-4 col-md-12 col-lg-6" style="background-color: blue"> <h1>Blue</h1> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="js/bootstrap.bundle.min.js"></script> </body> </html> function showLoading() { var myGrid = $("#myGrid").getKendoGrid(); kendo.ui.progress(myGrid, true); } .srt.sub.txt。 / p>

我将不胜感激。

2 个答案:

答案 0 :(得分:5)

最简单的方法是使用glob

chdir $directory;
my @files = glob '*.srt *.sub *.txt *.ass *.ssa';

另一种方法是使用readdir,但是您必须自己过滤文件,例如通过使用grep

open my $dir_handle, $directory or die $!;
my @files = grep /\.(?:srt|sub|txt|ass|ssa)\z/, readdir $dir_handle;

答案 1 :(得分:0)

如果您需要搜索整个目录树,请使用File::Find