LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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
 
LinkBack Search this Thread
Old 01-31-2006, 08:39 PM   #1
crapodino
Member
 
Registered: Aug 2005
Distribution: SuSE 10
Posts: 72

Rep: Reputation: 15
create a directory in c++


Hi: I use c++ with kdevelope in suse 10. I need to create folders (directories) and i couldn't find how to do it. I tried this:

system("md /home/mariano/tpmotor/src/new_folder")
or
system("md new_folder")

but it didn't work

how can i do it ??

thanks
 
Old 01-31-2006, 09:01 PM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Code:
#include <cstdlib>
...
system("mkdir a_new_dir");
hth
 
Old 01-31-2006, 09:03 PM   #3
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 46
i don't think there is "md"; use "mkdir"
 
Old 01-31-2006, 09:10 PM   #4
crapodino
Member
 
Registered: Aug 2005
Distribution: SuSE 10
Posts: 72

Original Poster
Rep: Reputation: 15
yessssssssssssss

thank you very much. it was mkdir.

as in a command line was md i thoungth that it was in c++ too

thanks
 
Old 01-31-2006, 09:54 PM   #5
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 46
No, you are precisely running things on the command line; but there is no command called "md" in Unix (perhaps you or your admin alias'ed it in bash or something).
 
Old 01-31-2006, 10:00 PM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
Originally Posted by spooon
No, you are precisely running things on the command line; but there is no command called "md" in Unix (perhaps you or your admin alias'ed it in bash or something).
No, there is a command called md in unix (preferably starting from solaris 2.4).
Its a pseduo device driver (generic - basically)supporting all the disk devices on solaris.
 
Old 01-31-2006, 10:08 PM   #7
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
No, you are precisely running things on the command line; but there is no command called "md" in Unix (perhaps you or your admin alias'ed it in bash or something).
from `man md`
md - Multiple Device driver aka Linux Software Raid

reagardless, it doesnt make directories

Last edited by xhi; 02-01-2006 at 08:17 AM.
 
Old 01-31-2006, 11:31 PM   #8
Stack
Member
 
Registered: Oct 2003
Distribution: FreeBSD
Posts: 325

Rep: Reputation: 30
Here is another arguably better way of doing what you want:
http://www.opengroup.org/onlinepubs/...ons/mkdir.html
 
Old 02-01-2006, 07:55 PM   #9
crapodino
Member
 
Registered: Aug 2005
Distribution: SuSE 10
Posts: 72

Original Poster
Rep: Reputation: 15
now i have another problem, with rmdir i can't erase a directory if it isn't empty. how can i erase a directory wich is not empy ? i don't want to erase element by element. instead, i would like to erase the whole folder. i search in man but it doesnt' say anything


thanks
 
Old 02-01-2006, 07:58 PM   #10
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by crapodino
now i have another problem, with rmdir i can't erase a directory if it isn't empty. how can i erase a directory wich is not empy ? i don't want to erase element by element. instead, i would like to erase the whole folder. i search in man but it doesnt' say anything


thanks
from `man rmdir`
--ignore-fail-on-non-empty
Normally rmdir will refuse to remove a directory that is not empty. This option causes rmdir to ignore the failure to remove a directory, if that
failure is due to the directory being non-empty. (New in fileutils-4.0.)

i typically use `rm -r` as it is shorter and does same thing
 
Old 02-01-2006, 08:09 PM   #11
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 46
Quote:
Originally Posted by xhi
from `man rmdir`
--ignore-fail-on-non-empty
Normally rmdir will refuse to remove a directory that is not empty. This option causes rmdir to ignore the failure to remove a directory, if that
failure is due to the directory being non-empty. (New in fileutils-4.0.)
Doesn't this just not remove the directory if it's not empty?
 
Old 02-01-2006, 08:18 PM   #12
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Spooon,
i stand corrected.. it does just ignore it by not doing anything.. not ignore the fact that it is not empty and delete it.. one of those options seen but not used.. and apparently misunderstood..

imo, `rm -r` would be the best way to go here..
 
Old 02-01-2006, 08:23 PM   #13
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
btw
I would think a param such as..
Code:
--silent-fail-on-non-empty
would be preferred, and much more fitting than the current rather obscure
Code:
--ignore-fail-on-non-empty
as ignore implies that it is ignoring the failure and is continuing with the removal. where silent or somthing similar would clearly say it is still failing but is silently doing so..
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a directory in C++ poeta_boy Programming 15 11-02-2011 01:53 PM
How to create new directory?? Jorine Programming 4 12-01-2004 12:38 AM
can't create new directory dummoi Linux - Newbie 4 06-24-2004 02:50 PM
Can't create new directory!!?? catty Linux - Newbie 7 10-06-2003 05:33 PM
Create a directory SnowSurfAir Linux - Software 15 07-21-2003 06:12 PM


All times are GMT -5. The time now is 08:47 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration