Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to find a file vaguely by file name by Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux how to find files according to the file name fuzzy", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux how to fuzzy search files according to the file name" bar!

Fnmatch int fnmatch (const char * pattern, const char * string, int flags); the parameter indicates that FNM_NOESCAPE, if this flag is set, handles the backslash as normal characters rather than escape characters. FNM_PATHNAME if this flag is set, the slash in string only matches the slash in pattern, it does not match the asterisk (*) or question mark (?) Metacharacters also cannot match a bracket expression ([]) that contains a slash. FNM_PERIOD if this flag is set, the starting point in string must match the period in pattern. A period is considered the starting point, if it is the first character of string, or if FNM_PATHNAME is also set, the period immediately following the slash. FNM_FILE_NAME this is a synonym for FNM_PATHNAME GNU. FNM_LEADING_DIR if this flag (GNU extension) is set, the pattern must match the initial fragment of string that follows the slash. This flag is mainly for internal use by glibc and is only implemented under certain conditions. FNM_CASEFOLD if this flag (GNU extension) is set, pattern matching ignores case.

The return value 0:string matches pattern; FNM_NOMATCH: no match, or other non-zero values, if an error occurs.

Example code is as follows:

# include # include using namespace std; vectorWildcardSearch (const char* pattern,const char* filePath) {vectorres; struct dirent * entry; DIR * dir; int ret; dir = opendir (filePath); if (dir! = NULL) {while ((entry = readdir (dir))! = NULL) {ret = fnmatch (pattern,entry- > dumbname.FNMASPATHNAME | FNM_PERIOD) If (ret = = 0) {res.push_back (entry- > d_name);} else {continue;} closedir (dir); return res } int main (int argc,char*argv []) {vectortmp; char* pattern = argv [1]; char* path = argv [2]; tmp = WildcardSearch (pattern,path); for (int iTun0) I for example:. / test "2018-*.bmp". / path thank you for reading, the above is the content of "Linux how to fuzzy find files according to the file name", after the study of this article, I believe you have a deeper understanding of how Linux fuzzy search files according to the file name, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report