LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-22-2006, 11:35 PM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
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.
 
Old 04-23-2006, 12:23 AM   #2
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
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").
 
Old 04-23-2006, 12:31 AM   #3
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, ataraxia.

I also need a "mv" function

Thanks.
 
Old 04-23-2006, 12:35 AM   #4
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
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);
 
Old 04-23-2006, 01:07 AM   #5
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
Quote:
Originally Posted by ataraxia
Just do the "cp" stuff and then "unlink" the old file:
Better use rename(2).
 
Old 04-23-2006, 05:05 AM   #6
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, ataraxia, addy86.
The last thing I need is "rmdir". Does unlink suit me?

Thanks.
 
Old 04-23-2006, 05:40 AM   #7
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
No. Don't call unlink() on directories; use rmdir(2) instead. Better yet, use remove(3).
 
Old 04-23-2006, 05:42 AM   #8
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, addy86.
 
Old 04-23-2006, 07:41 AM   #9
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
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.
 
Old 04-23-2006, 08:49 AM   #10
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
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
 
Old 04-23-2006, 09:48 AM   #11
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, addy86.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 04:40 AM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
"ifcfg-ethx" and "network-functions" files peok Linux - Networking 12 08-13-2003 06:06 PM

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

All times are GMT -5. The time now is 06:37 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