Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Remove() for directories

Reply
Thread Tools

Remove() for directories

 
 
Quentin Pope
Guest
Posts: n/a
 
      08-25-2011
Hi I am trying to delete a directory portably, using remove(). However it
always returns EOF and doesn't delete the directory.

Is there another function I should be using?

Thanks
QP
 
Reply With Quote
 
 
 
 
Joe Pfeiffer
Guest
Posts: n/a
 
      08-25-2011
Quentin Pope <> writes:

> Hi I am trying to delete a directory portably, using remove(). However it
> always returns EOF and doesn't delete the directory.
>
> Is there another function I should be using?


As somebody else has posted, this can't be done portably. It's an OS
question, not a C question.

In a Unix-derived OS, you want the rmdir() call.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      08-25-2011
Quentin Pope <> writes:

> Hi I am trying to delete a directory portably, using remove(). However it
> always returns EOF and doesn't delete the directory.


ISO C doesn't say anything about directories, but POSIX says that
remove() will delete a directory. That's about as portable as
you're going to get.

Are you sure that the directory is empty?
--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      08-25-2011
On August 25, 2011 12:29, in comp.lang.c, wrote:

> Hi I am trying to delete a directory portably, using remove().


remove() is not a portable function, and does not exist in ISO C. For that
matter, the concept of directories also does not exist in ISO C,

> However it always returns EOF


Not likely. You need to reread the documentation on that function.

For instance, if you use the POSIX remove() function, then it either returns
0 for success or -1 for failure. If it returns -1, then "errno is
set appropriately" for the error encountered.


> and doesn't delete the directory.
>
> Is there another function I should be using?


Perhaps. But then again, you probably should learn how to properly use the
function you first selected.

--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------


 
Reply With Quote
 
Joe Pfeiffer
Guest
Posts: n/a
 
      08-25-2011
Quentin Pope <> writes:

> Hi I am trying to delete a directory portably, using remove(). However it
> always returns EOF and doesn't delete the directory.
>
> Is there another function I should be using?


Taking a quick look at remove()... it's returning -1, which is of
course the same value as EOF, but isn't EOF. It also sets errno when an
error happens, so you ought to be able to use perror() to find out what
went wrong.
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      08-25-2011
Lew Pitcher <> writes:

> On August 25, 2011 12:29, in comp.lang.c, wrote:
>
>> Hi I am trying to delete a directory portably, using remove().

>
> remove() is not a portable function, and does not exist in ISO C.


Sorry, you're wrong. From C99 (but it wasn't new in C99):

7.19.4.1 The remove function

Synopsis
1 #include <stdio.h>
int remove(const char *filename);

Description
2 The remove function causes the file whose name is the string
pointed to by filename to be no longer accessible by that
name. A subsequent attempt to open that file using that name
will fail, unless it is created anew. If the file is open,
the behavior of the remove function is
implementation-defined.

Returns
3 The remove function returns zero if the operation succeeds,
nonzero if it fails.


> For that matter, the concept of directories also does not exist
> in ISO C,


You're right about that.

>> However it always returns EOF

>
> Not likely. You need to reread the documentation on that function.
> For instance, if you use the POSIX remove() function, then it either returns
> 0 for success or -1 for failure. If it returns -1, then "errno is
> set appropriately" for the error encountered.


EOF is commonly -1, so returning EOF on error is actually a
fairly likely outcome.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      08-25-2011
Joe Pfeiffer <> writes:

> Quentin Pope <> writes:
>
>> Hi I am trying to delete a directory portably, using remove(). However it
>> always returns EOF and doesn't delete the directory.
>>
>> Is there another function I should be using?

>
> As somebody else has posted, this can't be done portably. It's an OS
> question, not a C question.
>
> In a Unix-derived OS, you want the rmdir() call.


In a POSIX OS, remove() will remove a directory, just like
rmdir().

The Rationale even mentions UNIX in the description of remove():

7.19.4.1 The remove function

/usr/group provides the unlink system call to remove files.
The UNIX-specific definition of this function prompted the
C89 Committee to replace it with a portable function.

--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
Dr Nick
Guest
Posts: n/a
 
      08-25-2011
Quentin Pope <> writes:

> Hi I am trying to delete a directory portably, using remove(). However it
> always returns EOF and doesn't delete the directory.
>
> Is there another function I should be using?


What does errno (or perror for that matter) show the actual problem to
be?

Is the directory empty?
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
 
Reply With Quote
 
Quentin Pope
Guest
Posts: n/a
 
      08-25-2011
On Thu, 25 Aug 2011 10:52:17 -0600, Joe Pfeiffer wrote:

> Quentin Pope <> writes:
>
>> Hi I am trying to delete a directory portably, using remove(). However
>> it always returns EOF and doesn't delete the directory.
>>
>> Is there another function I should be using?

>
> Taking a quick look at remove()... it's returning -1, which is of
> course the same value as EOF, but isn't EOF. It also sets errno when an
> error happens, so you ought to be able to use perror() to find out what
> went wrong.


Hi perror() says :-
remove: Is a directory

This would suggest to me that remove cannot act on directories. My system
is GNU/Linux.

Cheers
QP
 
Reply With Quote
 
Quentin Pope
Guest
Posts: n/a
 
      08-25-2011
On Thu, 25 Aug 2011 10:52:17 -0600, Joe Pfeiffer wrote:

> Quentin Pope <> writes:
>
>> Hi I am trying to delete a directory portably, using remove(). However
>> it always returns EOF and doesn't delete the directory.
>>
>> Is there another function I should be using?

>
> Taking a quick look at remove()... it's returning -1, which is of
> course the same value as EOF, but isn't EOF. It also sets errno when an
> error happens, so you ought to be able to use perror() to find out what
> went wrong.


Hi perror() says :-
remove: Is a directory

This would suggest to me that remove cannot act on directories. My system
is GNU/Linux.

Cheers
QP
 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Directories and Physical directories Paul M Fin MCAD 4 06-27-2008 07:50 PM
virtual directories/physical directories in IIS Paul F ASP .Net 4 06-25-2008 04:04 PM
Multiple bin-directories with virtual directories? =?Utf-8?B?TGFzc2UgTmlsc3Nvbg==?= ASP .Net 0 11-09-2004 05:49 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments