LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-23-2010, 11:09 PM   #1
poojithas
LQ Newbie
 
Registered: Jun 2010
Location: Chennai, India
Distribution: Ubuntu 10.04
Posts: 22

Rep: Reputation: 0
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 ?
 
Old 12-23-2010, 11:20 PM   #2
Cultist
Member
 
Registered: Feb 2010
Location: Chicago, IL
Distribution: Slackware64 14.2
Posts: 779

Rep: Reputation: 105Reputation: 105
yep.

In the terminal, type
Quote:
rm -rf [directory]
and the directory and all its contents will be deleted.
 
Old 12-24-2010, 12:04 AM   #3
poojithas
LQ Newbie
 
Registered: Jun 2010
Location: Chennai, India
Distribution: Ubuntu 10.04
Posts: 22

Original Poster
Rep: Reputation: 0
I'm looking for function to use in C program ( using gcc ).
 
Old 12-24-2010, 12:22 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
How about this:
Code:
system ("rm -rf xyz");
 
Old 12-24-2010, 06:17 AM   #5
poojithas
LQ Newbie
 
Registered: Jun 2010
Location: Chennai, India
Distribution: Ubuntu 10.04
Posts: 22

Original Poster
Rep: Reputation: 0
The system() call is very resource intensive as it does the fork() behind. Unfortunately I can't use it. Any other function ?
 
Old 12-24-2010, 10:40 AM   #6
raviteja_s
Member
 
Registered: Jun 2010
Location: India
Distribution: Redhat
Posts: 68

Rep: Reputation: 1
try this

rimdir()
{

echo `rm -rf dirname`
return
}
 
Old 12-24-2010, 11:20 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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!
 
Old 12-24-2010, 11:22 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by raviteja_s View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A script within a folder to delete the folder, script, and the folder's contents Cyberman Programming 15 10-17-2007 07:32 AM
How do I delete a folder? Ordinary12 Fedora 17 05-03-2007 07:03 PM
Delete Linked List Function Mistro116@yahoo.com Programming 6 12-10-2005 02:43 PM
seems like I delete my /etc folder. bladehaze Debian 9 09-12-2005 11:47 AM
What is the delete function??? LegendBreath Linux - Newbie 3 04-20-2005 05:31 PM


All times are GMT -5. The time now is 12:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration