Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > removing files

Reply
Thread Tools

removing files

 
 
Anthony
Guest
Posts: n/a
 
      07-11-2003
Hi,

Removing files seems to be rather clumsy in C (not C++).

I am trying next piece of code to delete a file (under W32);

int errno;
errno = remove("FSelCancelled");

After exiting the app the file is still on the system, so not deleted at all.

If I check the return code, I see value for errno = -1.

On the several doc. pags for remove I see return codes 7 (EBIG), 13 (EACCESS) , etc, etc. till 18 (EXDEV), but not an error code -1.

So, what's wrong ?

Thanks.
Anthony

 
Reply With Quote
 
 
 
 
Pieter Droogendijk
Guest
Posts: n/a
 
      07-11-2003
On Fri, 11 Jul 2003 10:39:08 +0200, Anthony wrote:
> Hi,
>
> Removing files seems to be rather clumsy in C (not C++).
>
> I am trying next piece of code to delete a file (under W32);
>
> int errno;
> errno = remove("FSelCancelled");
>
> After exiting the app the file is still on the system, so not deleted
> at all.
>
> If I check the return code, I see value for errno = -1.
>
> On the several doc. pags for remove I see return codes 7 (EBIG), 13
> (EACCESS) , etc, etc. till 18 (EXDEV), but not an error code -1.
>
> So, what's wrong ?
>
> Thanks.
> Anthony
>


You're mixing up return value and error code. I'll quote the man page:
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and
errno is set appropriately.

if remove() returns -1, check errno. You can use perror() to print the
last error in a human-readable way. These human-readable strings are
stored in *sys_errlist[], defined in errno.h, if you have something
against perror().

#include <stdio.h>
int main ()
{
if (remove ("somefile") < -1) perror ("removing file");
else printf ("i'm happy\n");
}

--
main(int c,char*k,char*s){c>0?main(0,"adceoX$_k6][^hn","-7\
0#05&'40$.6'+).3+1%30"),puts(""):*s?c=!c?-*sputchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1))s=0);return!s?10:10+*k;}
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-11-2003
"Anthony" <(E-Mail Removed)> wrote (11 Jul 2003) in news:bem06m$6dt$1
@sunrise.wldelft.nl / comp.lang.c:

> Hi,
>
> Okay, thanks for that info.
>
> Small problem that still remains, is that I have a GUI based
> app, what means that I don't see the printed error message
> from the perror function.
>
> Is there any way to use a proper function, returning an
> error string telling me what's wrong.


strerror().
I can't believe that someone who doesn't know about perror and
strerror has the gall to post
> Removing files seems to be rather clumsy in C (not C++).>

Knowing something about C should be a requirement for people who want
to complain about it.




--
Martin Ambuhl
Returning soon to the
Fourth Largest City in America
 
Reply With Quote
 
Darrell Grainger
Guest
Posts: n/a
 
      07-11-2003
On Fri, 11 Jul 2003, Anthony wrote:

> Hi,
>
> Removing files seems to be rather clumsy in C (not C++).
>
> I am trying next piece of code to delete a file (under W32);
>
> int errno;
> errno = remove("FSelCancelled");
>
> After exiting the app the file is still on the system, so not deleted at all.
>
> If I check the return code, I see value for errno = -1.


You overwrote the errno variable with the result of remove(). Try this:

int result;
result = remove("FSelCancelled");
if(result == -1) {
printf("errno: %d\n", errno);
}

> On the several doc. pags for remove I see return codes 7 (EBIG), 13 (EACCESS) , etc, etc. till 18 (EXDEV), but not an error code -1.
>
> So, what's wrong ?
>
> Thanks.
> Anthony
>


--
main(){int j=1234;char t[]=":@abcdefghijklmnopqrstuvwxyz.\n",*i=
"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}

 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      07-12-2003
On 11 Jul 2003 13:54:10 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) (Darrell Grainger)
wrote in comp.lang.c:

> On Fri, 11 Jul 2003, Anthony wrote:
>
> > Hi,
> >
> > Removing files seems to be rather clumsy in C (not C++).
> >
> > I am trying next piece of code to delete a file (under W32);
> >
> > int errno;
> > errno = remove("FSelCancelled");
> >
> > After exiting the app the file is still on the system, so not deleted at all.
> >
> > If I check the return code, I see value for errno = -1.

>
> You overwrote the errno variable with the result of remove(). Try this:
>
> int result;
> result = remove("FSelCancelled");
> if(result == -1) {
> printf("errno: %d\n", errno);
> }


The standard does not require the remove function to put a value in
errno.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
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
Removing Duplicate Files RBF Computer Support 13 09-09-2013 07:06 PM
Removing GPO setting from XP machine after removing from Domain Piet Slaghekke Computer Support 4 01-02-2007 08:58 PM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
removing code blocks from autogenerated files with ant ion Java 2 02-08-2005 07:22 PM
Outlook Express removing files I want to send rpaulsen Computer Support 2 06-30-2004 02:03 PM



Advertisments