Removing files from C code

I need to delete several hundred files inside my C code. I use delete in a loop. Is there a faster way to do this than using delete? I ask about this because I cannot give wildchars using "remove".

+5
source share
2 answers

No, there is no faster way than using remove()- or unlink()on POSIX systems - in a loop.

The system rmdoes this too - at least in the simple non-recursive case where the names are specified on the command line. The shell expands the metacharacters, and rm(in) coolly continues to delete what was said to be deleted, unaware of the catastrophic notation *.*that was used on the command line. (In the recursive case, it uses a function such as nftw()to traverse the directory structure in order of depth and recall on unlink(), to delete files and rmdir()to delete (now-empty) directories.)

POSIX provides functions ( glob()and wordexp()) for creating lists of file names from the metacharacters used in the shell (POSIX), plus fnmatch()to find out if the name matches the pattern.

+10

system, , * . , , , unlink() , ( ). .

0

All Articles