c0m4
c0m4

Reputation: 4453

How to delete a file from a C++ app without console window in Windows?

I need to delete a temporary file from my C++ windows application (developed in Borland C++ Builder). Currently I use a simple:

system("del tempfile.tmp");

This causes a console window to flash in front of my app and it doesn't look very professional. How do I do this without the console window?

Upvotes: 5

Views: 6062

Answers (3)

SmacL
SmacL

Reputation: 22922

Or, even the standard C library function int remove( const char *path );.

Upvotes: 16

Roger Nelson
Roger Nelson

Reputation: 1912

For a slightly more portable (I.e. that works in both Windows and UNIX), I use unlink() or the ISO conformant _unlink() in io.h (unlink() for UNIX include unistd.h)
Remove() actually calls _unlink().

Upvotes: 2

Paul Stephenson
Paul Stephenson

Reputation: 69400

It sounds like you need the Win32 function DeleteFile(). You will need to #include <windows.h> to use it.

Upvotes: 15

Related Questions