I used what's below to delete a directory. It only deletes the directory if it's empty. How could I delete a directory and it's contents?

#include <unistd.h>

int main()
    return 0;
Member Avatar for iamthwee

What OS are you using?

What OS are you using?

What OS use C:\? :)

I'm using XP.

The command for deleting folder not empty is:

rmdir /S/Q directory.
The /S will delete directories not empty but asking for Y/N.
The /Q will not ask at all.

Yeah, I don't think those work in a C program though.

>Yeah, I don't think those work in a C program though.
Nope, you have to invoke them with system() calls, which is basically getting the operating system to do the task for you, although it does work...

This page uses a somewhat-ugly solution to achieve what you want, although the advantage is that you stay away from system() calls.

I see, thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.