[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

to delete file with visual studio c

Posted on 2004-10-03
5
Medium Priority
?
256 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 59

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 59

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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.
Progress
Introduction to Processes

656 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