LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-14-2011, 10:56 PM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Rep: Reputation: Disabled
deleting folder


Hi all,

in my pgm i need to delete a folder ..........

here is my code

Code:
if (system("rm -rf $m_sSessionFolder")==0)
             cout << "folder succesfully deleted" <<endl;
        else
             cout<<"folder delete failed"<<endl;
pgm snapshot during debugging
Code:
(gdb) p m_sSessionFolder
$1 = {static npos = 4294967295, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
    _M_p = 0x8edd81c "/home/shamjs/.File1/dir1"}}

193             if (system("rm -rf $m_sSessionFolder")==0)
(gdb)
[Detaching after fork from child process 6181. (Try `set detach-on-fork off'.)]
194                  cout << "folder succesfully deleted" <<endl;
but after execution of above code ,the folder dir1 is not getting deleted ,dir1 has 2 files within it...........

whether i have to give any extra options in rm command

waiting for your reply...........

Last edited by shamjs; 12-15-2011 at 03:09 AM.
 
Old 12-15-2011, 04:53 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
How could the shell know what is in $m_sSessionFolder variable ? Seems a dangerous thing to do..
 
Old 12-15-2011, 05:35 AM   #3
shamjs
Member
 
Registered: Sep 2011
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Cedrik View Post
How could the shell know what is in $m_sSessionFolder variable ? Seems a dangerous thing to do..
plz suggest me what alternative i need to do in order to delete the directory and its content....
 
Old 12-15-2011, 05:48 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Look at the following man pages: unlink(2), rmdir(2) and remove(3). The numbers in brackets are section numbers and you use them like this: man 2 unlink.
 
Old 12-15-2011, 05:51 AM   #5
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by shamjs View Post
plz suggest me what alternative i need to do in order to delete the directory and its content....
Linux has unlink and rmdir functions provided by OS, and C/C++ has remove functions provided by <stdio.h>. Use them instead of calling "system" from C++ program.

P.S> Damn it. Got ninja'd by Nylex.
 
  


Reply



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
Cannot login after deleting /tmp folder balajis Linux - Newbie 4 08-26-2011 09:21 PM
Deleting a folder using a script weeshalll Programming 5 12-07-2009 02:34 AM
Creating and deleting folder/documentsproblem in samba directory. gaman Linux - Newbie 1 04-16-2008 02:36 AM
Deleting folder content Azhrarn Linux - Software 4 04-27-2006 04:07 AM
deleting a shared folder aymbpc Linux - Newbie 3 09-23-2003 06:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 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
Open Source Consulting | Domain Registration