Solved

to delete file with visual studio c

Posted on 2004-10-03
5
251 Views
Last Modified: 2010-04-17
hi, i need code that delete binary files in visual c
 thanks....
0
Comment
Question by:dror700
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 12213327
If you are working in Windows environment, just have to use WinAPI's DeleteFile() function.Something like:

DeleteFile("c:\\yourfolder\\yourfile.txt");

You can read more about DeleteFile() at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vclrfdeletefile.asp
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12213332
0
 
LVL 1

Expert Comment

by:ch0c
ID: 12214223
Or you can just use system("del C:\\folder\\file.txt"); (Or on *NIX, "rm /home/folder/file.txt")
That will work regardless of your build environment.
0
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 12214948
There is also the run time library function remove that goes back to pre Windows days

int remove ( const char * path)
int _wremove ( const wchar_t * path)

Function returns 0 if successful and -1 if not. If -1 then errno is set to EACSS (file read only or is open) ENOENT to indicate path not found.

This is for information only - if possible I would go with jaime_olivares recommendation.
0
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 12214959
Oh just a comment on system - it will work but your return values are not as significant as for DeleteFile and remove - with the latter you can get more information about why a delete failed.

Again for info purposes and not an attempt to lessen ch0c's suggestion which is still valid.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question