如何查找名称可能比预期名称长的文件?
我正在做一些测试,我有很多文件需要执行数据分析。我们的文件有命名约定,但有时有人会在文件名中添加更多内容。我正在寻找一种方法来查找名称的“核心”,然后保存整个文件名。
例如,我想查找 WIRA_Rabcd_RT
,但有人可能将文件名保存为 RED_GREEN_BLUE_WIRA_Rabcd_RT.txt
,所以我的文件夹将如下所示:
RED_GREEN_BLUE_WIRB_Rabcd_RT.txt
RED_GREEN_BLUE_WIRC_Rabcd_RT.txt
RED_GREEN_BLUE_WIRA_Rabcd_RT.txt ← I want to find this file, and open it.
RED_GREEN_BLUE_WIRF_Rabcd_RT.txt
RED_GREEN_BLUE_WIRG_Rabcd_RT.txt
RED_GREEN_BLUE_WIRT_Rabcd_RT.txt
RED_GREEN_BLUE_WIRW_Rabcd_RT.txt
RED_GREEN_BLUE_WIRQ_Rabcd_RT.txt
I am doing some testing where I have a lot of files that I need to perform data analysis on. We have a naming convention with our files, but sometime someone will add a little more to the file name. I'm looking for a way to look for the "core" of the name and then save the entire file name.
For example, I want to find WIRA_Rabcd_RT
, but someone may have saved the file name as RED_GREEN_BLUE_WIRA_Rabcd_RT.txt
, so my folder will look something like this:
RED_GREEN_BLUE_WIRB_Rabcd_RT.txt
RED_GREEN_BLUE_WIRC_Rabcd_RT.txt
RED_GREEN_BLUE_WIRA_Rabcd_RT.txt ← I want to find this file, and open it.
RED_GREEN_BLUE_WIRF_Rabcd_RT.txt
RED_GREEN_BLUE_WIRG_Rabcd_RT.txt
RED_GREEN_BLUE_WIRT_Rabcd_RT.txt
RED_GREEN_BLUE_WIRW_Rabcd_RT.txt
RED_GREEN_BLUE_WIRQ_Rabcd_RT.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
glob 函数似乎可以解决问题:
The glob function seems like it would do the trick:
在 Perl
TIMTOWTDI
中,这是另一种方式:@files
现在包含目录中与模式匹配的文件的名称。请注意,名称是相对于该目录的(存储为name
而不是dir/name
)。然后我经常使用File::chdir
模块将工作目录更改为$dir
以处理这些文件。例如:In Perl
TIMTOWTDI
so here is another way:@files
now contains the names of the files in the directory that matches the pattern. Note that the names are relative to that directory (stored asname
notdir/name
). I often then use theFile::chdir
module to change the working directory to$dir
to work on those files. For example: