-1

I am trying to simulate the behavior of linux commandline command

rm a1*.txt

using either wildcards or regular expressions, inside a C program (linux gcc).

Is there a standard way of doing that?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
mousomer
  • 2,632
  • 2
  • 24
  • 25

1 Answers1

4

If you're on a POSIX system, you can use glob() to expand such a pattern.

Then, of course, use the standard remove() function to do the deletion.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Nice. I hadn't come across glob before. I was thinking it'd be a call to nftw, which I suppose might still be a good bet if this was ever to expand to a recursive removal! – Joe Mar 31 '16 at 13:39