Skip to content

Instantly share code, notes, and snippets.

@PJB3005
Created January 16, 2022 18:33
Show Gist options
  • Save PJB3005/c74c2fdee62077463644b5f2f9561188 to your computer and use it in GitHub Desktop.
Save PJB3005/c74c2fdee62077463644b5f2f9561188 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <stdio.h>
void PrintErr(LPCWSTR func)
{
DWORD code = GetLastError();
LPWSTR errorText;
FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&errorText,
0,
NULL);
wprintf(L"%s failed (0x%X): %s", func, code, errorText);
}
int wmain(int argc, wchar_t** argv)
{
if (argc >= 2)
{
// Final directory in the path (CustomRegionSaveData) exists only in MO2 VFS.
if (!SetCurrentDirectoryW(L"D:\\steam_windows\\steamapps\\common\\Rain World\\UserData\\CustomRegionSaveData"))
{
PrintErr(L"SetCurrentDirectoryW");
return 1;
}
}
wchar_t curdir[300];
GetCurrentDirectoryW(300, curdir);
wprintf(L"Deleting foo.txt from %s\n", curdir);
if (!DeleteFileW(L"foo.txt"))
{
PrintErr(L"DeleteFileW");
return 1;
}
wprintf(L"Success!\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment