How to use the DeleteFile function using the Win32 API in C

1 Answer

0 votes
#include <windows.h>
#include <stdio.h>

int main(void) {
    LPCWSTR path = L"C:\\CPP_Examples\\example.txt";

    if (DeleteFileW(path)) {
        wprintf(L"File deleted successfully\n");
    }
    else {
        DWORD err = GetLastError();
        wprintf(L"DeleteFile failed. Error code: %lu\n", err);
    }

    return 0;
}




/*
run:

File deleted successfully

*/

 



answered Feb 14 by avibootz

Related questions

...