LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   function to delete a folder (https://www.linuxquestions.org/questions/linux-newbie-8/function-to-delete-a-folder-852141/)

poojithas 12-23-2010 11:09 PM

function to delete a folder
 
Hi,

Is there any function to delete a folder which has few files in it ?

I tried rimdir() bit it can only delete empty folders; unlink() can not delete directory entries. any other function ?

Cultist 12-23-2010 11:20 PM

yep.

In the terminal, type
Quote:

rm -rf [directory]
and the directory and all its contents will be deleted.

poojithas 12-24-2010 12:04 AM

I'm looking for function to use in C program ( using gcc ).

paulsm4 12-24-2010 12:22 AM

How about this:
Code:

system ("rm -rf xyz");

poojithas 12-24-2010 06:17 AM

The system() call is very resource intensive as it does the fork() behind. Unfortunately I can't use it. Any other function ?

raviteja_s 12-24-2010 10:40 AM

try this

rimdir()
{

echo `rm -rf dirname`
return
}

catkin 12-24-2010 11:20 AM

The operative part of the rm command source is line 343:
Code:

enum RM_status status = rm (file, &x);
Checking back to the includes, the most promisingly named is remove.h which, as hoped, has the rm function declaration. From there it is a short step browsing the git repository tree to remove.c where the rm function is defined from line 592 onwards. That source suggests it is non-trivial to do what you want!

Nylex 12-24-2010 11:22 AM

Quote:

Originally Posted by raviteja_s (Post 4202164)
try this

rimdir()
{

echo `rm -rf dirname`
return
}

Please read and understand what is being asked before giving an answer. The OP has already said that they want to do this in C, not Bash.


All times are GMT -5. The time now is 07:19 AM.