Link to home
Start Free TrialLog in
Avatar of dror700
dror700

asked on

to delete file with visual studio c

hi, i need code that delete binary files in visual c
 thanks....
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ch0c
ch0c

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.
Avatar of Julian Hansen
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.
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.