- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Using C to check file patten on directory
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:13 AM
тАО07-17-2006 02:13 AM
Just wondering is it possible to use C program to check whether files with certain pattern exists on a directory i.e. similar to using "ls pattern*"
regards
Henry
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:21 AM
тАО07-17-2006 02:21 AM
SolutionFile *f;
f = popen("ls xyz*","r");
would do the trick for you.
If you really want to do this then you use opendir() to open a directory, readdir() to read each directory entry, and then use the regcomp() and related functions for RE matching. Man regcomp for details.
- Tags:
- popen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:21 AM
тАО07-17-2006 02:21 AM
Re: Using C to check file patten on directory
As many ways as you care to write a string matching algorithm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:22 AM
тАО07-17-2006 02:22 AM
Re: Using C to check file patten on directory
Pattern matching uses regular expressions. This is easily done with 'Perl', 'awk' and 'sed'. If you would be more specific it would be easy to help.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:31 AM
тАО07-17-2006 02:31 AM
Re: Using C to check file patten on directory
of course regcomp()/regexec() is the interface that can do all the regular expression stuff.
But:
- if you need just the matching of a string like "ls fixedstring*", a simple strstr() in your readdir()-loop will do it.
- the regcmp()-pattern are that you use in grep, vi, .... These are NOT identical with the pattern in (k|c|tc)sh for filename globbing.
mfG Peter
- Tags:
- regcomp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 03:06 AM
тАО07-17-2006 03:06 AM
Re: Using C to check file patten on directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 03:08 AM
тАО07-17-2006 03:08 AM
Re: Using C to check file patten on directory
act just as you would do in normal shell command, e.g.
f = popen("ls xyz* 2>/dev/null","r");
mfG Peter