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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-23-2006, 12:35 AM
|
#1
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Rep:
|
C/C++ functions similar to BASH's "cp", "mv", "mkdir", etc?
I need to "mkdir" and "cp" from within an app. And this app must be cross-platform, that's why system ("mkdir ..."); doesn't suit me.
Any suggestion?
Thanks.
PS: The app is built upon wxWidgets lib.
|
|
|
04-23-2006, 01:23 AM
|
#2
|
Member
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296
Rep:
|
There is a "mkdir" system call:
Code:
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
For "cp" you will probably have to open the source file ("fopen"), create the destination file ("creat"), and copy the file contents ("fread" and "fwrite").
|
|
|
04-23-2006, 01:31 AM
|
#3
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
|
Thanks, ataraxia.
I also need a "mv" function
Thanks.
|
|
|
04-23-2006, 01:35 AM
|
#4
|
Member
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296
Rep:
|
Quote:
Originally Posted by kornerr
I also need a "mv" function
|
Just do the "cp" stuff and then "unlink" the old file:
Code:
#include <unistd.h>
int unlink(const char *pathname);
|
|
|
04-23-2006, 02:07 AM
|
#5
|
Member
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332
Rep:
|
Quote:
Originally Posted by ataraxia
Just do the "cp" stuff and then "unlink" the old file:
|
Better use rename(2).
|
|
|
04-23-2006, 06:05 AM
|
#6
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
|
Thanks, ataraxia, addy86.
The last thing I need is "rmdir". Does unlink suit me?
Thanks.
|
|
|
04-23-2006, 06:40 AM
|
#7
|
Member
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332
Rep:
|
No. Don't call unlink() on directories; use rmdir(2) instead. Better yet, use remove(3).
|
|
|
04-23-2006, 06:42 AM
|
#8
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
|
Thanks, addy86.
|
|
|
04-23-2006, 08:41 AM
|
#9
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
|
Well, "remove" calls "rmdir" when removing dirs. But "rmdir" removes dirs only when they're empty.
Is there a way to delete a dir with all the files it contains?
Thanks.
|
|
|
04-23-2006, 09:49 AM
|
#10
|
Member
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332
Rep:
|
You have to recursively delete the directory: delete any files you find in them; when you find a directory, recursively delete it, and so on.
http://www.cs.cf.ac.uk/Dave/C/node20.html
|
|
|
04-23-2006, 10:48 AM
|
#11
|
Member
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893
Original Poster
Rep:
|
Thanks, addy86.
|
|
|
All times are GMT -5. The time now is 03:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|