Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 15th, 2004, 5:07 PM   #1
willz99ta
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 willz99ta is on a distinguished road
Howdy,

I am looking for a command that would be able to delete a text file in a UNIX directory from a C application. Is there anyway to do this?

Thanks for your help,
Willz99ta
willz99ta is offline   Reply With Quote
Old Sep 15th, 2004, 5:10 PM   #2
Ashcroft
Programmer
 
Join Date: Sep 2004
Posts: 38
Rep Power: 0 Ashcroft is on a distinguished road
'unlink' is what you want.

Note that this decrements the link count on a file, so if there are multiple hardlinks to that file for some reason this will not delete it. Also if a process has the file open when you unlink it the directory entry will be removed but the file itself will continue to exist while the process has it open.
Ashcroft is offline   Reply With Quote
Old Sep 16th, 2004, 8:53 AM   #3
willz99ta
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 willz99ta is on a distinguished road
So this would delete the physical file in a UXIX directory, like the remove command does in ANSI-C?

Thanks for your help,
Willz99ta
willz99ta is offline   Reply With Quote
Old Sep 16th, 2004, 9:05 AM   #4
Ashcroft
Programmer
 
Join Date: Sep 2004
Posts: 38
Rep Power: 0 Ashcroft is on a distinguished road
Yeah 'unlink' is a unix syscall to remove files. 'remove' will do the exact same thing, it calls 'unlink' if the specified path is a file and 'rmdir' (another syscall) if the specified path is a directory.
Ashcroft is offline   Reply With Quote
Old Sep 18th, 2004, 12:49 PM   #5
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Type this on command line:

man 2 unlink

You will get all the details you need in using it.
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC