I have to remove few hundreds of files inside my C code. I use "remove" in a loop. Is there any faster way to do it than using "remove"? I ask this because I can't give wildchars using "remove".
Right-click your main hard drive (usually the C: drive) and select Properties. Click the Disk Cleanup button and you'll see a list of items that can be removed, including temporary files and more. For even more options, click Clean up system files. Tick the categories you want to remove, then click OK > Delete Files.
The remove function in C/C++ can be used to delete a file. The function returns 0 if files is deleted successfully, other returns a non-zero value. #include<stdio.h> int main() {
The remove() function takes the following parameter: filename - pointer to the C-string containing the name of the file along with the path to delete.
No, there isn't a quicker way than using remove()
- or unlink()
on POSIX systems - in a loop.
The system rm
command does that too - at least in the simple, non-recursive case where the names are given on the command line. The shell expands the metacharacters, and rm
(in)famously goes along deleting what it was told to delete, unaware of the disastrous *.*
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 depth-first order and repeated calls to unlink()
to remove the files and rmdir()
to remove the (now-empty) directories.)
POSIX does provide functions (glob()
and wordexp()
) to generate lists of file names from metacharacters as used in the (POSIX) shell, plus fnmatch()
to see whether a name matches a pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With