LinuxQuestions.org
Visit Jeremy's Blog.
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 09-30-2004, 04:28 PM   #1
drigz
Member
 
Registered: Apr 2004
Distribution: Gentoo ~x86
Posts: 407

Rep: Reputation: 30
C File Manipulation in Linux


I need c commands which can do the same as:
{mv,cp} {,-i}
mkdir -p

Currently I'm using system() but it gets very complicated with string separation and stuff. I figured I could do cp by opening the file, reading all its contents and writing it into the destination file (but I'd still need a delete command to do mv), but I have no idea how to do mkdir (I could do the -p activity if I new how to create directories.

Thanks
 
Old 09-30-2004, 05:38 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,408

Rep: Reputation: 108Reputation: 108
There's mkdir() call. You can read its manual this way: man 2 mkdir. I can't see an equivalent of -p option, so you'd need to write it yourselft (create directries in a loop). Deleting files can be done using unlink() call. Manpage: man 2 unlink.
 
Old 09-30-2004, 06:00 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 899

Rep: Reputation: 33
If you don't mind applying the GPL to your code, you can grab copy.c and copy.h from the coreutils package, which has functions to do the work of copying (basically what you already suggested - reading from and writing to files), but I think it would be more work than the system() calls...
 
Old 10-01-2004, 01:15 AM   #4
drigz
Member
 
Registered: Apr 2004
Distribution: Gentoo ~x86
Posts: 407

Original Poster
Rep: Reputation: 30
I was trying to find stuff out by looking at the code of busybox, as it's far simpler than coreutils.... thanks for the help though. Anyone know a function to delete a file?
 
Old 10-01-2004, 01:21 AM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 53
Mara gave you one:
Quote:
Deleting files can be done using unlink() call. Manpage: man 2 unlink.
 
Old 10-01-2004, 07:28 AM   #6
drigz
Member
 
Registered: Apr 2004
Distribution: Gentoo ~x86
Posts: 407

Original Poster
Rep: Reputation: 30
i thought that was directories.... sorry - thanks.
 
  


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
shell script: File Manipulation simon_qwl Programming 2 10-29-2005 03:40 PM
file manipulation with c C.Aymen Programming 2 09-01-2005 12:48 PM
File name manipulation with tr, concatination troubles goofyheadedpunk Programming 9 07-06-2004 02:39 AM
File manipulation of NTFS from RHat 9 javadudd Linux - Newbie 3 04-01-2004 08:21 PM
Some basic File Manipulation commands sureshp1980 Linux - General 2 09-24-2003 08:36 PM


All times are GMT -5. The time now is 03:06 PM.

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