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

1 Answer

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

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

    if (DeleteFileW(path)) {
        std::wcout << L"File deleted successfully\n";
    }
    else {
        std::wcout << L"DeleteFile failed. Error: " << GetLastError() << L"\n";
    }

    return 0;
}




/*
run:

File deleted successfully

*/

 



answered Feb 14 by avibootz

Related questions

...