?
Solved

to delete file with visual studio c

Posted on 2004-10-03
5
Medium Priority
?
254 Views
Last Modified: 2010-04-17
hi, i need code that delete binary files in visual c
 thanks....
0
Comment
Question by:dror700
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 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 58

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 58

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes
Suggested Courses

764 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