LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   wildcard characters for ls (https://www.linuxquestions.org/questions/programming-9/wildcard-characters-for-ls-588592/)

basak 10-01-2007 06:25 AM

wildcard characters for ls
 
Hi!

I am trying to implement linux "ls" command just with system calls and until now I have succeded in listing a directory (with a given full path )and taking information about the files in there by opendir,readdir,stat system calls.But I also want to handle the wildcard characters '*' and '?' in the search pattern.Namely select only files which match the pattern containing these wildcards.Is there an easy way in handling that?Thank you:)

choogendyk 10-01-2007 06:37 AM

I think you're going to have to tell us what language you are programming in. A little more detail is always useful in getting an answer.

basak 10-01-2007 06:43 AM

I am programming in c++.Thanks again.

osor 10-01-2007 03:52 PM

Quote:

Originally Posted by basak (Post 2909205)
But I also want to handle the wildcard characters '*' and '?' in the search pattern.Namely select only files which match the pattern containing these wildcards.

IIRC, most wildcard/globbing happens in the shell prior to executing ls (or any executable for that matter). For this, the shell uses the POSIX-specified glob() and wordexp().

Utilities like ls, however, may need to implement filename matching for correct unix-path expansion. In this case, one might use the POSIX-specified fnmatch().


All times are GMT -5. The time now is 07:58 PM.