Solved

to delete file with visual studio c

Posted on 2004-10-03
5
245 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 51

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 51

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now