473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

removing files

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

Nov 13 '05 #1
4 4302
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?-*s:(putchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1)):(s=0);return!s?10:10+*k;}
Nov 13 '05 #2
"Anthony" <An*****@work.nl> 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
Nov 13 '05 #3
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;}

Nov 13 '05 #4
On 11 Jul 2003 13:54:10 GMT, da*****@cs.toronto.edu (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
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: hokiegal99 | last post by:
This script works as I expect, except for the last section. I want the last section to actually remove all spaces from the front and/or end of filenames. For example, a file that was named " test ...
6
by: bart_nessux | last post by:
Hello, I have some Macbinary files on a PC. I want to recursively read these files and remove the first 128 bytes of the files if they contain the macbinary header info. I know how to read...
2
by: Howard Kaikow | last post by:
On a multiboot system, I've got: 1. Office XP installed under an OS installed on drive G. 2. Office 2003 and NS .NET 2003 installed under an OS installed on drive J. When booted to J, if I try...
2
by: Nick | last post by:
Hi there, What does someone have to do to remove localization from a form?? It just keeps coming back again! I would like to try to assure that the property stays to "False" and the language...
5
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
0
by: nhmark64 | last post by:
My PC was a completely screwed up mess. Nieither the unistall tool or the manual uninstall at http://msdn.microsoft.com/vstudio/support/uninstall/default.aspx worked. I also tried the VS...
9
by: David Pratt | last post by:
Hi. I'm trying to clean files for packaging on mac using os.path.walk and want to clean the .DS_Store files that are hidden from view but could end up in code that I produce. # Clean mac...
3
by: Kilicaslan Fatih | last post by:
When I push a button to trigger the code: def runCCCC(self, event): cmd_out = self.A_com() if App.runF != "": os.mkdir('C:\copiedFiles') for item in App.runF: App.beCopied = str(item)...
0
by: Adam Salisbury | last post by:
**To members of microsoft.public.dotnet.framework, apologies for the crosspost. I originally posted this message into that group however have since realised this may have been a better...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.