Search code examples
cshellwildcardlsexecvp

How to execvp ls *.txt in C


I'm having issues execvping the *.txt wildcard, and reading this thread - exec() any command in C - indicates that it's difficult because of "globbing" issues. Is there any easy way to get around this?

Here's what I'm trying to do:

char * array[] = {"ls", "*.txt", (char *) NULL };
execvp("ls", array);

Solution

  • you could use the system command:

    system("ls *.txt");
    

    to let the shell do the globbing for you.